Spaces:
Running
Running
Download apps/api/dist/admin/admin-moderation.service.js from Benaah/MicProtocol: direct link, hf CLI and curl.
- Browser
- Download file 7.15 kB
-
https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/admin/admin-moderation.service.js
- Command line
-
hf download hf://spaces/Benaah/MicProtocol/apps/api/dist/admin/admin-moderation.service.js
-
curl -L -o admin-moderation.service.js https://huggingface.co/spaces/Benaah/MicProtocol/resolve/main/apps/api/dist/admin/admin-moderation.service.js
7.15 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 AdminModerationService_1; | |
| Object.defineProperty(exports, "__esModule", { value: true }); | |
| exports.AdminModerationService = 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 AdminModerationService = AdminModerationService_1 = class AdminModerationService { | |
| prisma; | |
| audit; | |
| logger = new common_1.Logger(AdminModerationService_1.name); | |
| constructor(prisma, audit) { | |
| this.prisma = prisma; | |
| this.audit = audit; | |
| } | |
| async listAbuseReports(input = {}) { | |
| const limit = Math.min(Math.max(input.limit ?? 50, 1), 200); | |
| const where = { | |
| ...(input.status ? { status: input.status } : {}), | |
| ...(input.category ? { category: input.category } : {}), | |
| ...(input.targetType ? { targetType: input.targetType } : {}), | |
| }; | |
| const [total, items] = await Promise.all([ | |
| this.prisma.abuseReport.count({ where }), | |
| this.prisma.abuseReport.findMany({ | |
| where, | |
| orderBy: { createdAt: "desc" }, | |
| take: limit + 1, | |
| ...(input.cursor ? { skip: 1, cursor: { id: input.cursor } } : {}), | |
| select: { | |
| id: true, | |
| reporterUserId: true, | |
| targetType: true, | |
| targetId: true, | |
| category: true, | |
| details: true, | |
| status: true, | |
| resolution: true, | |
| handledById: true, | |
| resolvedAt: true, | |
| createdAt: true, | |
| }, | |
| }), | |
| ]); | |
| const hasMore = items.length > limit; | |
| const page = hasMore ? items.slice(0, limit) : items; | |
| return { | |
| items: page.map((r) => ({ | |
| id: r.id, | |
| reporterUserId: r.reporterUserId, | |
| targetType: r.targetType, | |
| targetId: r.targetId, | |
| category: r.category, | |
| status: r.status, | |
| resolution: r.resolution, | |
| handledById: r.handledById, | |
| resolvedAt: r.resolvedAt, | |
| createdAt: r.createdAt, | |
| })), | |
| total, | |
| nextCursor: hasMore ? page[page.length - 1]?.id ?? null : null, | |
| }; | |
| } | |
| async getAbuseReport(reportId) { | |
| const report = await this.prisma.abuseReport.findUnique({ | |
| where: { id: reportId }, | |
| }); | |
| if (!report) | |
| throw new common_1.NotFoundException(`Abuse report ${reportId} not found`); | |
| return report; | |
| } | |
| async resolveReport(reportId, resolution, handlerUserId, status) { | |
| const report = await this.prisma.abuseReport.findUnique({ | |
| where: { id: reportId }, | |
| select: { id: true, status: true, resolution: true, targetType: true, targetId: true }, | |
| }); | |
| if (!report) | |
| throw new common_1.NotFoundException(`Abuse report ${reportId} not found`); | |
| if (report.status === "resolved") | |
| throw new common_1.BadRequestException("Report is already resolved"); | |
| const updated = await this.prisma.abuseReport.update({ | |
| where: { id: reportId }, | |
| data: { | |
| status: (status ?? "resolved"), | |
| resolution, | |
| handledById: handlerUserId, | |
| resolvedAt: new Date(), | |
| }, | |
| }); | |
| await this.audit.log({ | |
| userId: handlerUserId, | |
| action: "admin.moderation.resolve", | |
| entityType: "AbuseReport", | |
| entityId: reportId, | |
| metadata: { | |
| targetType: report.targetType, | |
| targetId: report.targetId, | |
| before: { status: report.status, resolution: report.resolution }, | |
| after: { status: updated.status, resolution }, | |
| }, | |
| }); | |
| return updated; | |
| } | |
| async takedown(reportId, handlerUserId, reason) { | |
| const report = await this.prisma.abuseReport.findUnique({ | |
| where: { id: reportId }, | |
| select: { id: true, status: true, targetType: true, targetId: true }, | |
| }); | |
| if (!report) | |
| throw new common_1.NotFoundException(`Abuse report ${reportId} not found`); | |
| const updated = await this.prisma.abuseReport.update({ | |
| where: { id: reportId }, | |
| data: { | |
| status: "resolved", | |
| resolution: reason || "takedown", | |
| handledById: handlerUserId, | |
| resolvedAt: new Date(), | |
| }, | |
| }); | |
| await this.audit.log({ | |
| userId: handlerUserId, | |
| action: "admin.moderation.takedown", | |
| entityType: report.targetType, | |
| entityId: report.targetId, | |
| metadata: { | |
| reportId, | |
| reason, | |
| before: { status: report.status }, | |
| after: { status: "resolved", resolution: "takedown" }, | |
| }, | |
| }); | |
| return updated; | |
| } | |
| }; | |
| exports.AdminModerationService = AdminModerationService; | |
| __decorate([ | |
| (0, admin_permission_decorator_1.requireAdminPermission)(shared_types_1.AdminPermission.MODERATION_RESOLVE), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [String, String, String, String]), | |
| __metadata("design:returntype", Promise) | |
| ], AdminModerationService.prototype, "resolveReport", null); | |
| __decorate([ | |
| (0, admin_permission_decorator_1.requireAdminPermission)(shared_types_1.AdminPermission.MODERATION_TAKEDOWN), | |
| __metadata("design:type", Function), | |
| __metadata("design:paramtypes", [String, String, String]), | |
| __metadata("design:returntype", Promise) | |
| ], AdminModerationService.prototype, "takedown", null); | |
| exports.AdminModerationService = AdminModerationService = AdminModerationService_1 = __decorate([ | |
| (0, common_1.Injectable)(), | |
| __metadata("design:paramtypes", [prisma_service_1.PrismaService, | |
| audit_service_1.AuditService]) | |
| ], AdminModerationService); | |
| //# sourceMappingURL=admin-moderation.service.js.map |