UNPKG

@elsikora/nestjs-crud-automator

Version:

A library for automating the creation of CRUD operations in NestJS.

35 lines (31 loc) 1.51 kB
'use strict'; var constant = require('../../constant/utility/dto/constant.js'); /** * Retrieves the configuration for property decorators based on method, metadata, and DTO type. * Allows for custom overrides defined in the property metadata and merges them with * defaults from the appropriate strategy. * @param {M} method - The API route type (CREATE, DELETE, GET, etc.) * @param {TApiPropertyDescribeProperties} metadata - The property metadata * @param {D} dtoType - The type of DTO (REQUEST, RESPONSE, etc.) * @param {string} propertyName - The name of the property * @returns {TApiPropertyDescribeDtoProperties} The merged decorator configuration * @throws {Error} When no strategy is found for the DTO type * @template M - The API route type * @template D - The DTO type */ // eslint-disable-next-line @elsikora/typescript/no-unnecessary-type-parameters const DtoGetDecoratorConfig = (method, metadata, dtoType, propertyName) => { const strategy = constant.DTO_UTILITY_CONSTANT.DTO_STRATEGIES[dtoType]; if (!strategy) { throw new Error(`Unknown DTO type ${dtoType}`); } let config = strategy.getDecoratorConfig(method, metadata); const properties = metadata.properties?.[method]; if (properties && properties[dtoType]) { const customConfig = properties[dtoType]; config = { ...config, ...customConfig }; } return config; }; exports.DtoGetDecoratorConfig = DtoGetDecoratorConfig; //# sourceMappingURL=get-decorator-config.utility.js.map