@elsikora/nestjs-crud-automator
Version:
A library for automating the creation of CRUD operations in NestJS.
28 lines (25 loc) • 1.54 kB
JavaScript
import { DTO_UTILITY_CONSTANT } from '../../constant/utility/dto/constant.js';
import { ErrorException } from '../error-exception.utility.js';
/**
* Factory function that generates appropriate property decorators based on property type.
* Uses factories defined in DTO_UTILITY_CONSTANT to create the correct decorator for each property type.
* @param {TApiPropertyDescribeProperties} metadata - Metadata describing the property
* @param {IApiEntity<E>} entity - The entity metadata
* @param {TApiPropertyDescribeDtoProperties} config - Configuration for the decorator
* @param {EApiRouteType} method - The API route type (CREATE, DELETE, GET, etc.)
* @param {EApiDtoType} dtoType - The type of DTO (REQUEST, RESPONSE, etc.)
* @param {string} propertyName - The name of the property
* @param {Record<string, Type<unknown>>} [generatedDTOs] - Optional record of dynamically generated DTOs
* @returns {PropertyDecorator} The generated property decorator
* @throws {Error} When property type has no registered factory
* @template E - The entity type
*/
function DtoGenerateDecorator(metadata, entity, config, method, dtoType, propertyName, generatedDTOs) {
const factory = DTO_UTILITY_CONSTANT.PROPERTY_DECORATOR_FACTORIES[metadata.type];
if (!factory) {
throw ErrorException(`Unknown property type ${metadata.type}`);
}
return factory.create(metadata, entity, config, method, dtoType, propertyName, generatedDTOs);
}
export { DtoGenerateDecorator };
//# sourceMappingURL=generate-decorator.utility.js.map