UNPKG

ncrudify

Version:

Configurable CRUD module for NestJS and Mongoose.

125 lines 4.99 kB
"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); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigController = void 0; const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const config_service_1 = require("./config.service"); let ConfigController = class ConfigController { constructor(configService) { this.configService = configService; } getAll() { return this.configService.getAll(); } async updateConfig(model, updates) { await this.configService.updateConfig(model, updates); await this.configService.load(); return { success: true, model, updates }; } async reload() { await this.configService.load(); return { success: true, message: "Configuration cache reloaded." }; } }; exports.ConfigController = ConfigController; __decorate([ (0, common_1.Get)(), (0, swagger_1.ApiOperation)({ summary: "Get the current configuration cache", description: "Returns the cached configuration of all models and their enabled routes.", }), (0, swagger_1.ApiResponse)({ status: 200, description: "Configuration cache retrieved successfully.", schema: { example: { User: { enabled: true, routes: { create: true, update: false, delete: true }, props: { otherProp: "value" }, }, }, }, }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", void 0) ], ConfigController.prototype, "getAll", null); __decorate([ (0, common_1.Put)(":model"), (0, swagger_1.ApiOperation)({ summary: "Update configuration for a specific model", description: "Updates enabled status or specific route flags for the given model. Automatically creates the record if it does not exist.", }), (0, swagger_1.ApiParam)({ name: "model", description: "Model name ", example: "User", }), (0, swagger_1.ApiBody)({ description: "Partial configuration object for the given model.", schema: { example: { enabled: true, routes: { create: true, createBulk: true, findAll: true, findOne: true, put: true, update: true, updateBulk: true, delete: true, deleteSoft: true, deleteBulk: true, restore: true, restoreBulk: true, count: true, }, props: { otherProp: "value" }, }, }, }), (0, swagger_1.ApiResponse)({ status: 200, description: "Configuration updated successfully.", }), __param(0, (0, common_1.Param)("model")), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], ConfigController.prototype, "updateConfig", null); __decorate([ (0, common_1.Post)("reload"), (0, common_1.HttpCode)(common_1.HttpStatus.OK), (0, swagger_1.ApiOperation)({ summary: "Reload configuration cache", description: "Forces a reload of the configuration cache from the database.", }), (0, swagger_1.ApiResponse)({ status: 200, description: "Configuration cache reloaded successfully.", }), __metadata("design:type", Function), __metadata("design:paramtypes", []), __metadata("design:returntype", Promise) ], ConfigController.prototype, "reload", null); exports.ConfigController = ConfigController = __decorate([ (0, swagger_1.ApiTags)("Config"), (0, common_1.Controller)("config"), __metadata("design:paramtypes", [config_service_1.ConfigService]) ], ConfigController); //# sourceMappingURL=config.controller.js.map