@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
37 lines (34 loc) • 1.56 kB
JavaScript
import { BadRequestException } from '@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 BadRequestException("INVALID_PARAMETERS");
}
const value = parameterRecord[mapping.parameter];
if (value === undefined || value === null) {
throw new 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;
}
export { ApiControllerReadScopeWhere };
//# sourceMappingURL=scope.utility.js.map