template-saas/apps/backend/dist/modules/notifications/notifications.controller.js
rckrdmrd 26f0e52ca7 feat: Initial commit - template-saas
Template base para proyectos SaaS multi-tenant.

Estructura inicial:
- apps/backend (NestJS API)
- apps/frontend (React/Vite)
- apps/database (PostgreSQL DDL)
- docs/ (Documentación)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-07 04:41:24 -06:00

182 lines
8.9 KiB
JavaScript

"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.NotificationsController = void 0;
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const notifications_service_1 = require("./services/notifications.service");
const dto_1 = require("./dto");
const jwt_auth_guard_1 = require("../auth/guards/jwt-auth.guard");
const permissions_guard_1 = require("../rbac/guards/permissions.guard");
const current_user_decorator_1 = require("../auth/decorators/current-user.decorator");
let NotificationsController = class NotificationsController {
constructor(notificationsService) {
this.notificationsService = notificationsService;
}
async getMyNotifications(user, page, limit, unreadOnly) {
return this.notificationsService.findAllForUser(user.id, user.tenant_id, {
page: page || 1,
limit: limit || 20,
unreadOnly: unreadOnly || false,
});
}
async getUnreadCount(user) {
const count = await this.notificationsService.getUnreadCount(user.id, user.tenant_id);
return { count };
}
async markAsRead(id, user) {
return this.notificationsService.markAsRead(id, user.id, user.tenant_id);
}
async markAllAsRead(user) {
const count = await this.notificationsService.markAllAsRead(user.id, user.tenant_id);
return { message: `${count} notificaciones marcadas como leídas` };
}
async delete(id, user) {
await this.notificationsService.delete(id, user.id, user.tenant_id);
return { message: 'Notificación eliminada' };
}
async getPreferences(user) {
return this.notificationsService.getPreferences(user.id, user.tenant_id);
}
async updatePreferences(user, dto) {
return this.notificationsService.updatePreferences(user.id, user.tenant_id, dto);
}
async sendNotification(dto, user) {
return this.notificationsService.create(dto, user.tenant_id);
}
async sendFromTemplate(dto, user) {
return this.notificationsService.sendFromTemplate(dto, user.tenant_id);
}
async getTemplates() {
return this.notificationsService.findAllTemplates();
}
async getTemplate(code) {
return this.notificationsService.findTemplateByCode(code);
}
};
exports.NotificationsController = NotificationsController;
__decorate([
(0, common_1.Get)(),
(0, swagger_1.ApiOperation)({ summary: 'Get my notifications' }),
(0, swagger_1.ApiQuery)({ name: 'page', required: false, type: Number }),
(0, swagger_1.ApiQuery)({ name: 'limit', required: false, type: Number }),
(0, swagger_1.ApiQuery)({ name: 'unreadOnly', required: false, type: Boolean }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Query)('page')),
__param(2, (0, common_1.Query)('limit')),
__param(3, (0, common_1.Query)('unreadOnly')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Number, Number, Boolean]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "getMyNotifications", null);
__decorate([
(0, common_1.Get)('unread-count'),
(0, swagger_1.ApiOperation)({ summary: 'Get unread notifications count' }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "getUnreadCount", null);
__decorate([
(0, common_1.Patch)(':id/read'),
(0, swagger_1.ApiOperation)({ summary: 'Mark notification as read' }),
__param(0, (0, common_1.Param)('id')),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "markAsRead", null);
__decorate([
(0, common_1.Post)('read-all'),
(0, swagger_1.ApiOperation)({ summary: 'Mark all notifications as read' }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "markAllAsRead", null);
__decorate([
(0, common_1.Delete)(':id'),
(0, swagger_1.ApiOperation)({ summary: 'Delete notification' }),
__param(0, (0, common_1.Param)('id')),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "delete", null);
__decorate([
(0, common_1.Get)('preferences'),
(0, swagger_1.ApiOperation)({ summary: 'Get my notification preferences' }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "getPreferences", null);
__decorate([
(0, common_1.Patch)('preferences'),
(0, swagger_1.ApiOperation)({ summary: 'Update my notification preferences' }),
__param(0, (0, current_user_decorator_1.CurrentUser)()),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, dto_1.UpdatePreferencesDto]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "updatePreferences", null);
__decorate([
(0, common_1.Post)(),
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
(0, permissions_guard_1.RequirePermissions)('notifications:manage'),
(0, swagger_1.ApiOperation)({ summary: 'Send notification to user (admin)' }),
__param(0, (0, common_1.Body)()),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [dto_1.CreateNotificationDto, Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "sendNotification", null);
__decorate([
(0, common_1.Post)('template'),
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
(0, permissions_guard_1.RequirePermissions)('notifications:manage'),
(0, swagger_1.ApiOperation)({ summary: 'Send notification from template (admin)' }),
__param(0, (0, common_1.Body)()),
__param(1, (0, current_user_decorator_1.CurrentUser)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [dto_1.SendTemplateNotificationDto, Object]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "sendFromTemplate", null);
__decorate([
(0, common_1.Get)('templates'),
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
(0, permissions_guard_1.RequirePermissions)('notifications:manage'),
(0, swagger_1.ApiOperation)({ summary: 'List notification templates (admin)' }),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "getTemplates", null);
__decorate([
(0, common_1.Get)('templates/:code'),
(0, common_1.UseGuards)(permissions_guard_1.PermissionsGuard),
(0, permissions_guard_1.RequirePermissions)('notifications:manage'),
(0, swagger_1.ApiOperation)({ summary: 'Get notification template by code (admin)' }),
__param(0, (0, common_1.Param)('code')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], NotificationsController.prototype, "getTemplate", null);
exports.NotificationsController = NotificationsController = __decorate([
(0, swagger_1.ApiTags)('notifications'),
(0, common_1.Controller)('notifications'),
(0, common_1.UseGuards)(jwt_auth_guard_1.JwtAuthGuard),
(0, swagger_1.ApiBearerAuth)(),
__metadata("design:paramtypes", [notifications_service_1.NotificationsService])
], NotificationsController);
//# sourceMappingURL=notifications.controller.js.map