@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
34 lines (30 loc) • 1.68 kB
JavaScript
;
var methodName_utility = require('../get/method-name.utility.js');
var exception_utility = require('../../../error/exception.utility.js');
/**
* Creates controller methods dynamically.
* Gets the method name, checks if it's already defined, and either
* calls the implementation or throws an error if not implemented.
* @param {Record<string, (method: EApiRouteType, methodName: string, properties: IApiControllerProperties<E>, entityMetadata: IApiEntity<E>) => void>} thisTarget - The object containing method implementations
* @param {Record<string, unknown>} target - The target controller class to add methods to
* @param {EApiRouteType} method - The type of route (CREATE, DELETE, GET, etc.)
* @param {IApiControllerProperties<E>} properties - Controller configuration properties
* @param {IApiEntity<E>} entityMetadata - The entity metadata containing column information
* @returns {void}
* @throws {Error} When the reserved method is already defined or method implementation is missing
* @template E - The entity type
*/
function ApiControllerWriteMethod(thisTarget, target, method, properties, entityMetadata) {
const methodName = methodName_utility.ApiControllerGetMethodName(method);
if (target[methodName]) {
throw exception_utility.ErrorException(`Reserved method ${methodName} already defined`);
}
if (thisTarget[method]) {
thisTarget[method](method, methodName, properties, entityMetadata);
}
else {
throw exception_utility.ErrorException(`Method ${methodName} not implemented`);
}
}
exports.ApiControllerWriteMethod = ApiControllerWriteMethod;
//# sourceMappingURL=method.utility.js.map