@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
39 lines (35 loc) • 1.6 kB
JavaScript
;
var common = require('@nestjs/common');
/**
* Converts validated inherited path parameters into a direct entity where scope.
* @template E - Entity type owned by the generated route.
* @param {Partial<E> | undefined} parameters - Transformed route parameter object.
* @param {IApiControllerReadPlan} readPlan - Validated route-local read plan.
* @returns {FindOptionsWhere<E>} Direct entity scope derived from the route path.
* @throws {BadRequestException} When a required inherited parameter is missing.
*/
function ApiControllerReadScopeWhere(parameters, readPlan) {
const parameterRecord = parameters ?? {};
const scope = {};
for (const mapping of readPlan.parameters) {
if (!Object.hasOwn(parameterRecord, mapping.parameter)) {
throw new common.BadRequestException("INVALID_PARAMETERS");
}
const value = parameterRecord[mapping.parameter];
if (value === undefined || value === null) {
throw new common.BadRequestException("INVALID_PARAMETERS");
}
Object.defineProperty(scope, mapping.field, {
// eslint-disable-next-line @elsikora/typescript/naming-convention
configurable: true,
// eslint-disable-next-line @elsikora/typescript/naming-convention
enumerable: true,
value,
// eslint-disable-next-line @elsikora/typescript/naming-convention
writable: true,
});
}
return scope;
}
exports.ApiControllerReadScopeWhere = ApiControllerReadScopeWhere;
//# sourceMappingURL=scope.utility.js.map