feat: 完成 PRD 差距与修复,新增审核流与日志清理功能,支持出库信息与动态字段,优化 C 端用户体验
This commit is contained in:
@@ -2,7 +2,7 @@ import { Body, Controller, Delete, Get, Param, ParseIntPipe, Post, Put, Query }
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { RoleType } from '@artveris/shared';
|
||||
import { ArtworkService } from './artwork.service';
|
||||
import { CreateArtworkDto, QueryArtworkDto, UpdateArtworkDto } from './dto/artwork.dto';
|
||||
import { AuditArtworkDto, CreateArtworkDto, QueryArtworkDto, UpdateArtworkDto } from './dto/artwork.dto';
|
||||
import { Roles } from '../common/decorators/roles.decorator';
|
||||
import { CurrentUser, AuthUser } from '../common/decorators/current-user.decorator';
|
||||
|
||||
@@ -38,6 +38,17 @@ export class ArtworkController {
|
||||
return this.artworkService.update(id, dto);
|
||||
}
|
||||
|
||||
@Post(':id/audit')
|
||||
@Roles(RoleType.AUDITOR)
|
||||
@ApiOperation({ summary: '审核艺术品(通过/驳回,审核员)' })
|
||||
audit(
|
||||
@Param('id', ParseIntPipe) id: number,
|
||||
@Body() dto: AuditArtworkDto,
|
||||
@CurrentUser() user: AuthUser,
|
||||
) {
|
||||
return this.artworkService.audit(id, dto, user.id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Roles(RoleType.OPERATOR)
|
||||
@ApiOperation({ summary: '停用/删除艺术品(软删除)' })
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { ArtworkStatus, ErrorCode } from '@artveris/shared';
|
||||
import { AuditStatus, ErrorCode } from '@artveris/shared';
|
||||
import { PrismaService } from '../prisma/prisma.service';
|
||||
import { StorageService } from '../storage/storage.service';
|
||||
import { BusinessException } from '../common/exceptions/business.exception';
|
||||
import { buildPage } from '../common/utils/pagination.util';
|
||||
import { CreateArtworkDto, QueryArtworkDto, UpdateArtworkDto } from './dto/artwork.dto';
|
||||
import { AuditArtworkDto, CreateArtworkDto, QueryArtworkDto, UpdateArtworkDto } from './dto/artwork.dto';
|
||||
|
||||
interface MediaItem {
|
||||
key: string;
|
||||
@@ -54,6 +54,7 @@ export class ArtworkService {
|
||||
];
|
||||
}
|
||||
if (query.status) where.status = query.status;
|
||||
if (query.auditStatus) where.auditStatus = query.auditStatus;
|
||||
if (query.templateId) where.templateId = query.templateId;
|
||||
|
||||
const [rows, total] = await this.prisma.$transaction([
|
||||
@@ -105,6 +106,11 @@ export class ArtworkService {
|
||||
title: dto.title,
|
||||
artist: dto.artist,
|
||||
status: dto.status,
|
||||
// 内容变更需重新审核:编辑后回到待审核
|
||||
auditStatus: AuditStatus.PENDING,
|
||||
auditRemark: null,
|
||||
auditedBy: null,
|
||||
auditedAt: null,
|
||||
};
|
||||
if (dto.dynamicFields !== undefined) {
|
||||
data.dynamicFields = dto.dynamicFields as Prisma.InputJsonValue;
|
||||
@@ -116,6 +122,21 @@ export class ArtworkService {
|
||||
return this.get(id);
|
||||
}
|
||||
|
||||
// 审核:通过 / 驳回(审核员或超管)
|
||||
async audit(id: number, dto: AuditArtworkDto, auditorId: number) {
|
||||
await this.ensureExists(id);
|
||||
await this.prisma.artwork.update({
|
||||
where: { id },
|
||||
data: {
|
||||
auditStatus: dto.approved ? AuditStatus.APPROVED : AuditStatus.REJECTED,
|
||||
auditRemark: dto.remark ?? null,
|
||||
auditedBy: auditorId,
|
||||
auditedAt: new Date(),
|
||||
},
|
||||
});
|
||||
return this.get(id);
|
||||
}
|
||||
|
||||
async remove(id: number) {
|
||||
await this.ensureExists(id);
|
||||
await this.prisma.artwork.update({ where: { id }, data: { deletedAt: new Date() } });
|
||||
|
||||
@@ -11,7 +11,8 @@ import {
|
||||
MaxLength,
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
import { ArtworkStatus } from '@artveris/shared';
|
||||
import { IsBoolean } from 'class-validator';
|
||||
import { ArtworkStatus, AuditStatus } from '@artveris/shared';
|
||||
import { PaginationDto } from '../../common/dto/pagination.dto';
|
||||
|
||||
export class MediaItemDto {
|
||||
@@ -104,9 +105,26 @@ export class QueryArtworkDto extends PaginationDto {
|
||||
@IsEnum(ArtworkStatus)
|
||||
status?: ArtworkStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: '审核状态', enum: AuditStatus })
|
||||
@IsOptional()
|
||||
@IsEnum(AuditStatus)
|
||||
auditStatus?: AuditStatus;
|
||||
|
||||
@ApiPropertyOptional({ description: '模板 ID' })
|
||||
@IsOptional()
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
templateId?: number;
|
||||
}
|
||||
|
||||
export class AuditArtworkDto {
|
||||
@ApiProperty({ description: '是否通过' })
|
||||
@IsBoolean()
|
||||
approved!: boolean;
|
||||
|
||||
@ApiPropertyOptional({ description: '审核意见(驳回建议填写)' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@MaxLength(255)
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user