"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.ApplicationsController = void 0; const common_1 = require("@nestjs/common"); const swagger_1 = require("@nestjs/swagger"); const jwt_auth_guard_1 = require("../../../../core/auth/guards/jwt-auth.guard"); const current_user_guard_1 = require("../../../identity/presentation/guards/current-user.guard"); const get_applications_handler_1 = require("../../application/handlers/get-applications.handler"); const get_application_handler_1 = require("../../application/handlers/get-application.handler"); const create_application_handler_1 = require("../../application/handlers/create-application.handler"); const update_application_handler_1 = require("../../application/handlers/update-application.handler"); const delete_application_handler_1 = require("../../application/handlers/delete-application.handler"); const get_me_applications_handler_1 = require("../../application/handlers/get-me-applications.handler"); let ApplicationsController = class ApplicationsController { getApplicationsHandler; getApplicationHandler; createApplicationHandler; updateApplicationHandler; deleteApplicationHandler; getMeApplicationsHandler; constructor(getApplicationsHandler, getApplicationHandler, createApplicationHandler, updateApplicationHandler, deleteApplicationHandler, getMeApplicationsHandler) { this.getApplicationsHandler = getApplicationsHandler; this.getApplicationHandler = getApplicationHandler; this.createApplicationHandler = createApplicationHandler; this.updateApplicationHandler = updateApplicationHandler; this.deleteApplicationHandler = deleteApplicationHandler; this.getMeApplicationsHandler = getMeApplicationsHandler; } async findAll(query) { const res = await this.getApplicationsHandler.execute({ page: query.page, limit: query.limit, search: query.search }); return { success: true, data: res.data.map(a => a.toResponse ? a.toResponse() : a), meta: { total: res.total } }; } async findOne(id) { const app = await this.getApplicationHandler.execute(id); return { success: true, data: app.toResponse(), meta: {} }; } async create(body) { const created = await this.createApplicationHandler.execute(body); return { success: true, data: created.toResponse(), meta: {} }; } async update(id, body) { const updated = await this.updateApplicationHandler.execute(id, body); return { success: true, data: updated.toResponse(), meta: {} }; } async remove(id) { await this.deleteApplicationHandler.execute(id); return { success: true, data: null, meta: {} }; } // Dashboard endpoint async me(req) { const ctx = req.raylabContext; const identity = ctx && ctx.identity ? ctx.identity : {}; const applicationsClaimList = identity.applications || []; const res = await this.getMeApplicationsHandler.execute(applicationsClaimList); return { success: true, data: res.data.map(a => a.toResponse ? a.toResponse() : a), meta: { total: res.total } }; } }; exports.ApplicationsController = ApplicationsController; __decorate([ (0, common_1.Get)('applications'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard), (0, swagger_1.ApiOperation)({ summary: 'List applications' }), __param(0, (0, common_1.Query)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], ApplicationsController.prototype, "findAll", null); __decorate([ (0, common_1.Get)('applications/:id'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard), (0, swagger_1.ApiOperation)({ summary: 'Get application by id' }), __param(0, (0, common_1.Param)('id')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], ApplicationsController.prototype, "findOne", null); __decorate([ (0, common_1.Post)('applications'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard), (0, swagger_1.ApiOperation)({ summary: 'Create application' }), __param(0, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], ApplicationsController.prototype, "create", null); __decorate([ (0, common_1.Patch)('applications/:id'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard), (0, swagger_1.ApiOperation)({ summary: 'Update application' }), __param(0, (0, common_1.Param)('id')), __param(1, (0, common_1.Body)()), __metadata("design:type", Function), __metadata("design:paramtypes", [String, Object]), __metadata("design:returntype", Promise) ], ApplicationsController.prototype, "update", null); __decorate([ (0, common_1.Delete)('applications/:id'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard), (0, swagger_1.ApiOperation)({ summary: 'Delete application' }), __param(0, (0, common_1.Param)('id')), __metadata("design:type", Function), __metadata("design:paramtypes", [String]), __metadata("design:returntype", Promise) ], ApplicationsController.prototype, "remove", null); __decorate([ (0, common_1.Get)('me/applications'), (0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard, current_user_guard_1.CurrentUserGuard), (0, swagger_1.ApiOperation)({ summary: "Get current user's applications (filtered by Authentik claims)" }), __param(0, (0, common_1.Req)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], ApplicationsController.prototype, "me", null); exports.ApplicationsController = ApplicationsController = __decorate([ (0, swagger_1.ApiTags)('Applications'), (0, common_1.Controller)(), __metadata("design:paramtypes", [get_applications_handler_1.GetApplicationsHandler, get_application_handler_1.GetApplicationHandler, create_application_handler_1.CreateApplicationHandler, update_application_handler_1.UpdateApplicationHandler, delete_application_handler_1.DeleteApplicationHandler, get_me_applications_handler_1.GetMeApplicationsHandler]) ], ApplicationsController); //# sourceMappingURL=applications.controller.js.map