"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.Api = exports.PaginatedDto = exports.PaginatedVo = exports.ApiResponseVo = void 0; const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const api_optional_decorator_1 = require("./decorator/api_optional.decorator"); const is_number_or_number_str_1 = require("./decorator/is_number_or_number_str"); class ApiResponseVo { code; msg; success; data; constructor(code, data, msg = 'success') { this.code = code; this.msg = msg; this.success = code == 200 || code == 201; if (typeof data != 'undefined' && data != null) { this.data = data; } } } exports.ApiResponseVo = ApiResponseVo; class PaginatedVo { total; list; constructor(total, list) { this.total = total; this.list = list; } } exports.PaginatedVo = PaginatedVo; __decorate([ (0, swagger_1.ApiProperty)(), __metadata("design:type", Number) ], PaginatedVo.prototype, "total", void 0); class PaginatedDto { page; size; } exports.PaginatedDto = PaginatedDto; __decorate([ (0, api_optional_decorator_1.ApiOptional)({ default: 1, description: '页数' }), (0, is_number_or_number_str_1.IsNumberOrNumberStr)(), __metadata("design:type", Number) ], PaginatedDto.prototype, "page", void 0); __decorate([ (0, api_optional_decorator_1.ApiOptional)({ default: 15, description: '页长度' }), (0, is_number_or_number_str_1.IsNumberOrNumberStr)(), __metadata("design:type", Number) ], PaginatedDto.prototype, "size", void 0); class Api { static success(data, msg) { return new ApiResponseVo(200, data, msg); } static successMsg(msg) { return new ApiResponseVo(200, null, msg); } static error(msg, code = 400) { return new ApiResponseVo(code, null, msg); } static pagination(list, total) { return new ApiResponseVo(200, new PaginatedVo(total, list)); } static ApiResponse(opt) { if (!opt?.model) { return (0, common_1.applyDecorators)((0, swagger_1.ApiOkResponse)({ schema: { required: ['code', 'msg', 'success'], properties: { code: { type: 'number', description: opt?.codeDescription || '200成功', }, success: { type: 'boolean', }, msg: { type: 'string', }, }, }, })); } return (0, common_1.applyDecorators)((0, swagger_1.ApiExtraModels)(opt.model), (0, swagger_1.ApiOkResponse)({ schema: { required: ['code', 'msg', 'success'], properties: { code: { type: 'number', description: opt.codeDescription || '200成功', }, success: { type: 'boolean', }, msg: { type: 'string', }, data: { $ref: (0, swagger_1.getSchemaPath)(opt.model), }, }, }, })); } static ApiPaginatedResponse(opt) { return (0, common_1.applyDecorators)((0, swagger_1.ApiExtraModels)(opt.model), (0, swagger_1.ApiOkResponse)({ schema: { allOf: [ { required: ['code', 'msg', 'success'], properties: { code: { type: 'number', description: opt.codeDescription || '200成功', }, success: { type: 'boolean', }, msg: { type: 'string', }, data: { type: 'object', required: ['total', 'list'], properties: { total: { type: 'number', }, list: { type: 'array', items: { $ref: (0, swagger_1.getSchemaPath)(opt.model) }, }, }, }, }, }, ], }, })); } } exports.Api = Api; //# sourceMappingURL=api.js.map