UNPKG

@elsikora/nestjs-crud-automator

Version:

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

110 lines (107 loc) 4.98 kB
import { __decorate, __metadata } from '../../external/tslib/tslib.es6.js'; import { LIST_DTO_CONSTANT } from '../../constant/dto/list.constant.js'; import { ApiPropertyNumber } from '../../decorator/api/property/number.decorator.js'; import { ApiPropertyObject } from '../../decorator/api/property/object.decorator.js'; import '../../enum/decorator/api/action.enum.js'; import '../../enum/decorator/api/authentication-type.enum.js'; import '../../enum/decorator/api/controller/load-relations-strategy.enum.js'; import '../../enum/decorator/api/controller/request-transformer-type.enum.js'; import '../../enum/decorator/api/dto-type.enum.js'; import '../../enum/decorator/api/function/type.enum.js'; import '../../enum/decorator/api/on-type.enum.js'; import '../../enum/decorator/api/property/data-type.enum.js'; import '../../enum/decorator/api/property/date/identifier.enum.js'; import '../../enum/decorator/api/property/date/type.enum.js'; import '../../enum/decorator/api/property/desribe-type.enum.js'; import { EApiPropertyNumberType } from '../../enum/decorator/api/property/number-type.enum.js'; import '../../enum/decorator/api/property/string-type.enum.js'; import '../../enum/decorator/api/route-type.enum.js'; import { PickType } from '@nestjs/swagger'; /** * Generates a DTO for paginated list responses with appropriate metadata. * Creates a class with count, currentPage, items, totalCount, and totalPages properties, * all properly decorated with Swagger and validation decorators. * @param {TDtoGenerateGetListResponseResourceClass} resourceClass - The class representing the entity being listed * @param {TDtoGenerateGetListResponseResourceClass} responseResourceClass - The response DTO class for individual items * @param {string} name - The name for the generated DTO class * @returns {Type<unknown>} A generated DTO class for paginated list responses */ function DtoGenerateGetListResponse(resourceClass, responseResourceClass, name) { class ApiListGetResponse extends PickType(resourceClass, []) { count; currentPage; items; totalCount; totalPages; } __decorate([ ApiPropertyNumber({ description: "Total number of items on page", entity: resourceClass, exampleValue: LIST_DTO_CONSTANT.MINIMUM_LIST_LENGTH, format: EApiPropertyNumberType.INTEGER, isResponse: true, maximum: LIST_DTO_CONSTANT.MAXIMUM_LIST_LENGTH, minimum: LIST_DTO_CONSTANT.MINIMUM_LIST_LENGTH, multipleOf: 1, }), __metadata("design:type", Number) ], ApiListGetResponse.prototype, "count", void 0); __decorate([ ApiPropertyNumber({ description: "Current page number", entity: resourceClass, exampleValue: LIST_DTO_CONSTANT.MINIMUM_LIST_PAGES_COUNT, format: EApiPropertyNumberType.INTEGER, isResponse: true, maximum: LIST_DTO_CONSTANT.MAXIMUM_LIST_PAGES_COUNT, minimum: LIST_DTO_CONSTANT.MINIMUM_LIST_PAGES_COUNT, multipleOf: 1, }), __metadata("design:type", Number) ], ApiListGetResponse.prototype, "currentPage", void 0); __decorate([ ApiPropertyObject({ entity: resourceClass, isArray: true, isResponse: true, isUniqueItems: true, maxItems: LIST_DTO_CONSTANT.MAXIMUM_LIST_LENGTH, minItems: LIST_DTO_CONSTANT.MINIMUM_LIST_LENGTH, type: responseResourceClass, }), __metadata("design:type", Array) ], ApiListGetResponse.prototype, "items", void 0); __decorate([ ApiPropertyNumber({ description: "Total number of items", entity: resourceClass, exampleValue: LIST_DTO_CONSTANT.MINIMUM_LIST_LENGTH, format: EApiPropertyNumberType.INTEGER, isResponse: true, maximum: LIST_DTO_CONSTANT.MAXIMUM_LIST_LENGTH, minimum: LIST_DTO_CONSTANT.MINIMUM_LIST_LENGTH, multipleOf: 1, }), __metadata("design:type", Number) ], ApiListGetResponse.prototype, "totalCount", void 0); __decorate([ ApiPropertyNumber({ description: "Total number of pages", entity: resourceClass, exampleValue: LIST_DTO_CONSTANT.MINIMUM_LIST_PAGES_COUNT, format: EApiPropertyNumberType.INTEGER, isResponse: true, maximum: LIST_DTO_CONSTANT.MAXIMUM_LIST_PAGES_COUNT, minimum: LIST_DTO_CONSTANT.MINIMUM_LIST_PAGES_COUNT, multipleOf: 1, }), __metadata("design:type", Number) ], ApiListGetResponse.prototype, "totalPages", void 0); Object.defineProperty(ApiListGetResponse, "name", { value: name, }); return ApiListGetResponse; } export { DtoGenerateGetListResponse }; //# sourceMappingURL=generate-get-list-response.utility.js.map