feat: 超级管理员修改艺术品自动通过审核

This commit is contained in:
Nixevol
2026-07-05 04:19:56 +08:00
parent af79627228
commit 1b1c83b4bf
4 changed files with 16 additions and 9 deletions
+13 -7
View File
@@ -2,7 +2,7 @@ import { Injectable } from '@nestjs/common';
import { InjectQueue } from '@nestjs/bullmq';
import { Prisma } from '@prisma/client';
import { Queue } from 'bullmq';
import { ArtworkRevisionStatus, ArtworkStatus, AuditStatus, ErrorCode, QUEUE_NAMES } from '@artveris/shared';
import { ArtworkRevisionStatus, ArtworkStatus, AuditStatus, ErrorCode, QUEUE_NAMES, RoleType } from '@artveris/shared';
import { PrismaService } from '../prisma/prisma.service';
import { StorageService } from '../storage/storage.service';
import { BusinessException } from '../common/exceptions/business.exception';
@@ -17,6 +17,7 @@ import {
QueryArtworkRevisionDto,
UpdateArtworkDto,
} from './dto/artwork.dto';
import type { AuthUser } from '../common/decorators/current-user.decorator';
interface MediaItem {
key: string;
@@ -266,7 +267,8 @@ export class ArtworkService {
};
}
async update(id: number, dto: UpdateArtworkDto, userId: number) {
async update(id: number, dto: UpdateArtworkDto, user: AuthUser) {
const userId = user.id;
const current = await this.getSnapshot(id);
const nextStatus = dto.status === ArtworkStatus.DRAFT ? ArtworkStatus.ACTIVE : dto.status ?? current.artwork.status;
const afterSnapshot: ArtworkSnapshot = {
@@ -284,6 +286,7 @@ export class ArtworkService {
const artwork = await this.ensureExists(id);
const shouldApplyDirectly = artwork.status !== ArtworkStatus.ACTIVE || artwork.auditStatus !== AuditStatus.APPROVED;
const shouldAutoApprove = user.role === RoleType.SUPER_ADMIN;
if (!this.hasSnapshotChanged(current, afterSnapshot)) {
throw new BusinessException(ErrorCode.VALIDATION_FAILED, '作品内容未发生变化,无需提交审核', 400);
}
@@ -299,17 +302,20 @@ export class ArtworkService {
reason: revisionReason,
beforeSnapshot: current as unknown as Prisma.InputJsonObject,
afterSnapshot: afterSnapshot as unknown as Prisma.InputJsonObject,
status: ArtworkRevisionStatus.PENDING,
status: shouldAutoApprove ? ArtworkRevisionStatus.APPROVED : ArtworkRevisionStatus.PENDING,
auditRemark: null,
submittedBy: userId,
reviewedBy: shouldAutoApprove ? userId : null,
reviewedAt: shouldAutoApprove ? new Date() : null,
},
});
if (shouldApplyDirectly) {
if (shouldAutoApprove || shouldApplyDirectly) {
await this.applySnapshot(tx, id, afterSnapshot, {
auditStatus: AuditStatus.PENDING,
auditStatus: shouldAutoApprove ? AuditStatus.APPROVED : AuditStatus.PENDING,
auditRemark: null,
auditedBy: null,
auditedAt: null,
auditedBy: shouldAutoApprove ? userId : null,
auditedAt: shouldAutoApprove ? new Date() : null,
});
await tx.artworkRevision.update({ where: { id: revision.id }, data: { afterSnapshot: afterSnapshot as unknown as Prisma.InputJsonObject } });
}