Spaces:
Running
Running
Download apps/api/dist/admin/admin-comms.service.js from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 6.36 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/admin/admin-comms.service.js
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/dist/admin/admin-comms.service.js
-
curl -L -o admin-comms.service.js https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/admin/admin-comms.service.js
6.36 kB
| ; | |
| 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 AdminCommsService_1; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.AdminCommsService = void 0; | |
| const common_1 = require("@nestjs/common"); | |
| const prisma_service_1 = require("../prisma/prisma.service"); | |
| const audit_service_1 = require("../audit/audit.service"); | |
| const shared_types_1 = require("@micprotocol/shared-types"); | |
| const admin_permission_decorator_1 = require("../common/decorators/admin-permission.decorator"); | |
| let AdminCommsService = AdminCommsService_1 = class AdminCommsService { | |
| prisma; | |
| audit; | |
| logger = new common_1.Logger(AdminCommsService_1.name); | |
| constructor(prisma, audit) { | |
| this.prisma = prisma; | |
| this.audit = audit; | |
| } | |
| async listAnnouncements() { | |
| const items = await this.prisma.announcement.findMany({ | |
| orderBy: { createdAt: "desc" }, | |
| }); | |
| return items.map((a) => ({ | |
| id: a.id, | |
| title: a.title, | |
| body: a.body, | |
| audience: a.audience, | |
| severity: a.severity, | |
| status: a.status, | |
| publishedAt: a.publishedAt, | |
| expiresAt: a.expiresAt, | |
| createdById: a.createdById, | |
| createdAt: a.createdAt, | |
| })); | |
| } | |
| async createAnnouncement(title, body, audience, severity, status, publishedAt, expiresAt, createdById) { | |
| const announcement = await this.prisma.announcement.create({ | |
| data: { | |
| title, | |
| body, | |
| audience: audience, | |
| severity, | |
| status, | |
| publishedAt, | |
| expiresAt, | |
| createdById, | |
| }, | |
| }); | |
| await this.audit.log({ | |
| userId: createdById, | |
| action: "admin.announcements.write", | |
| entityType: "Announcement", | |
| entityId: announcement.id, | |
| metadata: { title, severity, status }, | |
| }); | |
| return announcement; | |
| } | |
| async updateAnnouncement(id, patch, actorUserId) { | |
| const existing = await this.prisma.announcement.findUnique({ | |
| where: { id }, | |
| select: { id: true, title: true, status: true }, | |
| }); | |
| if (!existing) | |
| throw new common_1.NotFoundException(`Announcement ${id} not found`); | |
| const data = {}; | |
| if (patch.title !== undefined) | |
| data.title = patch.title; | |
| if (patch.body !== undefined) | |
| data.body = patch.body; | |
| if (patch.audience !== undefined) | |
| data.audience = patch.audience; | |
| if (patch.severity !== undefined) | |
| data.severity = patch.severity; | |
| if (patch.status !== undefined) | |
| data.status = patch.status; | |
| if (patch.publishedAt !== undefined) | |
| data.publishedAt = patch.publishedAt; | |
| if (patch.expiresAt !== undefined) | |
| data.expiresAt = patch.expiresAt; | |
| const updated = await this.prisma.announcement.update({ where: { id }, data }); | |
| await this.audit.log({ | |
| userId: actorUserId, | |
| action: "admin.announcements.write", | |
| entityType: "Announcement", | |
| entityId: id, | |
| metadata: { before: { title: existing.title, status: existing.status }, after: patch }, | |
| }); | |
| return updated; | |
| } | |
| async archiveAnnouncement(id, actorUserId) { | |
| const existing = await this.prisma.announcement.findUnique({ | |
| where: { id }, | |
| select: { id: true, status: true }, | |
| }); | |
| if (!existing) | |
| throw new common_1.NotFoundException(`Announcement ${id} not found`); | |
| if (existing.status === "archived") | |
| throw new common_1.BadRequestException("Announcement is already archived"); | |
| const updated = await this.prisma.announcement.update({ | |
| where: { id }, | |
| data: { status: "archived" }, | |
| }); | |
| await this.audit.log({ | |
| userId: actorUserId, | |
| action: "admin.announcements.write", | |
| entityType: "Announcement", | |
| entityId: id, | |
| metadata: { before: { status: existing.status }, after: { status: "archived" } }, | |
| }); | |
| return updated; | |
| } | |
| }; | |
| exports.AdminCommsService = AdminCommsService; | |
| __decorate([ | |
| (0, admin_permission_decorator_1.requireAdminPermission)(shared_types_1.AdminPermission.ANNOUNCEMENTS_WRITE), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [String, String, Object, String, String, Object, Object, String]), | |
| __metadata("design:returntype", Promise) | |
| ], AdminCommsService.prototype, "createAnnouncement", null); | |
| __decorate([ | |
| (0, admin_permission_decorator_1.requireAdminPermission)(shared_types_1.AdminPermission.ANNOUNCEMENTS_WRITE), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [String, Object, String]), | |
| __metadata("design:returntype", Promise) | |
| ], AdminCommsService.prototype, "updateAnnouncement", null); | |
| __decorate([ | |
| (0, admin_permission_decorator_1.requireAdminPermission)(shared_types_1.AdminPermission.ANNOUNCEMENTS_WRITE), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [String, String]), | |
| __metadata("design:returntype", Promise) | |
| ], AdminCommsService.prototype, "archiveAnnouncement", null); | |
| exports.AdminCommsService = AdminCommsService = AdminCommsService_1 = __decorate([ | |
| (0, common_1.Injectable)(), | |
| __metadata("design:paramtypes", [prisma_service_1.PrismaService, | |
| audit_service_1.AuditService]) | |
| ], AdminCommsService); | |
| //# sourceMappingURL=admin-comms.service.js.map |