json-api-nestjs
Version:
JsonApi Plugin for NestJs
35 lines • 1.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CheckItemEntityPipe = void 0;
const tslib_1 = require("tslib");
const common_1 = require("@nestjs/common");
const constants_1 = require("../../../../constants");
const helper_1 = require("../../helper");
class CheckItemEntityPipe {
currentEntity;
findOneRowEntity;
async transform(value) {
if (!this.findOneRowEntity || typeof this.findOneRowEntity !== 'function')
return value;
const result = await this.findOneRowEntity(this.currentEntity, value);
if (!result) {
const error = {
code: 'invalid_arguments',
message: `Resource '${(0, helper_1.getEntityName)(this.currentEntity)}' with id '${value}' does not exist`,
path: [],
};
throw new common_1.NotFoundException([error]);
}
return value;
}
}
exports.CheckItemEntityPipe = CheckItemEntityPipe;
tslib_1.__decorate([
(0, common_1.Inject)(constants_1.CURRENT_ENTITY),
tslib_1.__metadata("design:type", Object)
], CheckItemEntityPipe.prototype, "currentEntity", void 0);
tslib_1.__decorate([
(0, common_1.Inject)(constants_1.FIND_ONE_ROW_ENTITY),
tslib_1.__metadata("design:type", Object)
], CheckItemEntityPipe.prototype, "findOneRowEntity", void 0);
//# sourceMappingURL=check-item-entity.pipe.js.map