UNPKG

json-api-nestjs

Version:
35 lines 1.46 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ParseRelationshipNamePipe = void 0; const tslib_1 = require("tslib"); const common_1 = require("@nestjs/common"); const constants_1 = require("../../../../constants"); const helper_1 = require("../../helper"); class ParseRelationshipNamePipe { currentEntity; checkRelationName; transform(value) { if (!this.checkRelationName || typeof this.checkRelationName !== 'function') return value; const result = this.checkRelationName(this.currentEntity, value); if (!result) { const error = { code: 'invalid_arguments', message: `Relation '${value}' does not exist in resource '${(0, helper_1.getEntityName)(this.currentEntity)}'`, path: [], }; throw new common_1.UnprocessableEntityException([error]); } return value; } } exports.ParseRelationshipNamePipe = ParseRelationshipNamePipe; tslib_1.__decorate([ (0, common_1.Inject)(constants_1.CURRENT_ENTITY), tslib_1.__metadata("design:type", Object) ], ParseRelationshipNamePipe.prototype, "currentEntity", void 0); tslib_1.__decorate([ (0, common_1.Inject)(constants_1.CHECK_RELATION_NAME), tslib_1.__metadata("design:type", Function) ], ParseRelationshipNamePipe.prototype, "checkRelationName", void 0); //# sourceMappingURL=parse-relationship-name.pipe.js.map