feat: 支持控制出库时间轴显示
This commit is contained in:
@@ -21,6 +21,7 @@ function createHarness() {
|
||||
auditStatus: data.auditStatus,
|
||||
dynamicFields: data.dynamicFields,
|
||||
images: data.images,
|
||||
showOutboundTimeline: data.showOutboundTimeline,
|
||||
traceNodes: [],
|
||||
certificates: [],
|
||||
})),
|
||||
@@ -107,6 +108,20 @@ describe('ArtworkService.create approval policy', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults outbound timeline visibility to false in the record and revision snapshot', async () => {
|
||||
const { service, tx } = createHarness();
|
||||
|
||||
await service.create(
|
||||
{ templateId: 1, title: 'default timeline visibility', status: ArtworkStatus.ACTIVE } as any,
|
||||
user(RoleType.SUPER_ADMIN),
|
||||
);
|
||||
|
||||
expect(tx.artwork.create.mock.calls[0][0].data.showOutboundTimeline).toBe(false);
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showOutboundTimeline,
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
function updateHarness() {
|
||||
const current = {
|
||||
artwork: {
|
||||
@@ -149,6 +164,38 @@ function updateHarness() {
|
||||
}
|
||||
|
||||
describe('ArtworkService.update approval policy', () => {
|
||||
it('applies a super-admin outbound timeline visibility change immediately', async () => {
|
||||
const { service, tx, applySnapshot } = updateHarness();
|
||||
|
||||
await service.update(7, { showOutboundTimeline: true } as any, user(RoleType.SUPER_ADMIN));
|
||||
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showOutboundTimeline,
|
||||
).toBe(true);
|
||||
expect(applySnapshot).toHaveBeenCalledWith(
|
||||
tx,
|
||||
7,
|
||||
expect.objectContaining({
|
||||
artwork: expect.objectContaining({ showOutboundTimeline: true }),
|
||||
}),
|
||||
expect.objectContaining({ auditStatus: AuditStatus.APPROVED, auditedBy: 9 }),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps an operator outbound timeline visibility change in the pending snapshot', async () => {
|
||||
const { service, tx, applySnapshot } = updateHarness();
|
||||
|
||||
await service.update(7, { showOutboundTimeline: true } as any, user(RoleType.OPERATOR));
|
||||
|
||||
expect(
|
||||
tx.artworkRevision.create.mock.calls[0][0].data.afterSnapshot.artwork.showOutboundTimeline,
|
||||
).toBe(true);
|
||||
expect(tx.artworkRevision.create.mock.calls[0][0].data.status).toBe(
|
||||
ArtworkRevisionStatus.PENDING,
|
||||
);
|
||||
expect(applySnapshot).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('applies a super-admin revision immediately and records who superseded the pending revision', async () => {
|
||||
const { service, tx, applySnapshot, enqueueWatermarks } = updateHarness();
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ interface ArtworkSnapshot {
|
||||
status: ArtworkStatus;
|
||||
dynamicFields: Record<string, unknown>;
|
||||
images: MediaItem[];
|
||||
showOutboundTimeline: boolean;
|
||||
};
|
||||
traceNodes: TraceNodeSnapshot[];
|
||||
certificates: CertificateSnapshot[];
|
||||
@@ -187,6 +188,7 @@ export class ArtworkService {
|
||||
auditedAt: reviewedAt,
|
||||
dynamicFields: (dto.dynamicFields ?? {}) as Prisma.InputJsonValue,
|
||||
images: (dto.images ?? []) as unknown as Prisma.InputJsonValue,
|
||||
showOutboundTimeline: dto.showOutboundTimeline ?? false,
|
||||
createdBy: userId,
|
||||
traceNodes: traceNodes.length
|
||||
? {
|
||||
@@ -435,6 +437,7 @@ export class ArtworkService {
|
||||
status: nextStatus,
|
||||
dynamicFields: dto.dynamicFields ?? current.artwork.dynamicFields,
|
||||
images: (dtoImages ?? current.artwork.images) as MediaItem[],
|
||||
showOutboundTimeline: dto.showOutboundTimeline ?? current.artwork.showOutboundTimeline ?? false,
|
||||
},
|
||||
traceNodes: dtoNodes ?? current.traceNodes,
|
||||
certificates: dtoCerts ?? current.certificates,
|
||||
@@ -645,6 +648,7 @@ export class ArtworkService {
|
||||
status: string;
|
||||
dynamicFields: Prisma.JsonValue | null;
|
||||
images: Prisma.JsonValue | null;
|
||||
showOutboundTimeline?: boolean;
|
||||
traceNodes: Array<{
|
||||
nodeType: string;
|
||||
title: string;
|
||||
@@ -671,6 +675,7 @@ export class ArtworkService {
|
||||
status: record.status as ArtworkStatus,
|
||||
dynamicFields: (record.dynamicFields as Record<string, unknown>) ?? {},
|
||||
images: (Array.isArray(record.images) ? record.images : []) as unknown as MediaItem[],
|
||||
showOutboundTimeline: record.showOutboundTimeline ?? false,
|
||||
},
|
||||
traceNodes: record.traceNodes
|
||||
.sort((a, b) => a.sortOrder - b.sortOrder)
|
||||
@@ -713,6 +718,7 @@ export class ArtworkService {
|
||||
status: snapshot.artwork.status,
|
||||
dynamicFields: this.normalizeJson(snapshot.artwork.dynamicFields ?? {}),
|
||||
images: this.normalizeMedia(snapshot.artwork.images),
|
||||
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
|
||||
},
|
||||
traceNodes: snapshot.traceNodes.map((node, index) => ({
|
||||
nodeType: node.nodeType,
|
||||
@@ -812,6 +818,7 @@ export class ArtworkService {
|
||||
status: snapshot.artwork.status,
|
||||
dynamicFields: snapshot.artwork.dynamicFields as Prisma.InputJsonObject,
|
||||
images: snapshot.artwork.images as unknown as Prisma.InputJsonValue,
|
||||
showOutboundTimeline: snapshot.artwork.showOutboundTimeline ?? false,
|
||||
...auditData,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -34,6 +34,11 @@ export class MediaItemDto {
|
||||
}
|
||||
|
||||
export class CreateArtworkDto {
|
||||
@ApiPropertyOptional({ description: '是否在客户端时间轴显示本件出库记录', default: false })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
showOutboundTimeline?: boolean;
|
||||
|
||||
@ApiProperty({ description: '模板 ID' })
|
||||
@Type(() => Number)
|
||||
@IsInt()
|
||||
@@ -158,6 +163,11 @@ export class CreateArtworkCertificateDto {
|
||||
}
|
||||
|
||||
export class UpdateArtworkDto {
|
||||
@ApiPropertyOptional({ description: '是否在客户端时间轴显示本件出库记录' })
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
showOutboundTimeline?: boolean;
|
||||
|
||||
@ApiPropertyOptional({ description: '作品名称' })
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
|
||||
@@ -1,7 +1,30 @@
|
||||
import { ArtworkStatus, AuditStatus, TraceCodeStatus } from '@artveris/shared';
|
||||
import { PublicTraceService } from './public-trace.service';
|
||||
|
||||
function createHarness() {
|
||||
function createHarness(options: {
|
||||
artworkStatus?: ArtworkStatus;
|
||||
showOutboundTimeline?: boolean;
|
||||
withOutbound?: boolean;
|
||||
} = {}) {
|
||||
const outbound = options.withOutbound
|
||||
? {
|
||||
outTime: new Date('2026-07-16T08:00:00.000Z'),
|
||||
remark: 'outbound note',
|
||||
images: [
|
||||
{
|
||||
id: 1n,
|
||||
fileKey: 'outbound/1.jpg',
|
||||
fileName: '1.jpg',
|
||||
mimeType: 'image/jpeg',
|
||||
size: 1024n,
|
||||
width: 800,
|
||||
height: 600,
|
||||
sortOrder: 0,
|
||||
},
|
||||
],
|
||||
_count: { images: 1 },
|
||||
}
|
||||
: null;
|
||||
const code = {
|
||||
id: 1n,
|
||||
shortCode: '482731000001',
|
||||
@@ -18,14 +41,16 @@ function createHarness() {
|
||||
auditStatus: AuditStatus.APPROVED,
|
||||
deletedAt: null,
|
||||
},
|
||||
outbound: null,
|
||||
outbound,
|
||||
};
|
||||
const artwork = {
|
||||
...code.artwork,
|
||||
status: options.artworkStatus ?? ArtworkStatus.DRAFT,
|
||||
title: '草稿作品',
|
||||
artist: null,
|
||||
images: [],
|
||||
dynamicFields: null,
|
||||
showOutboundTimeline: options.showOutboundTimeline ?? false,
|
||||
template: { fields: [] },
|
||||
traceNodes: [],
|
||||
certificates: [],
|
||||
@@ -76,3 +101,32 @@ describe('PublicTraceService draft visibility', () => {
|
||||
expect(prisma.outboundImage.findMany).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('PublicTraceService outbound timeline visibility', () => {
|
||||
it.each([
|
||||
{ showOutboundTimeline: false, expectedSystemNodes: 0 },
|
||||
{ showOutboundTimeline: true, expectedSystemNodes: 1 },
|
||||
])(
|
||||
'keeps outbound data while producing $expectedSystemNodes system timeline node(s)',
|
||||
async ({ showOutboundTimeline, expectedSystemNodes }) => {
|
||||
const { service } = createHarness({
|
||||
artworkStatus: ArtworkStatus.ACTIVE,
|
||||
showOutboundTimeline,
|
||||
withOutbound: true,
|
||||
});
|
||||
|
||||
const result = await service.preview('482731000001', 'inactive');
|
||||
|
||||
expect(result.status).toBe('OK');
|
||||
expect((result as any).outbound).toEqual(
|
||||
expect.objectContaining({
|
||||
outTime: new Date('2026-07-16T08:00:00.000Z'),
|
||||
remark: 'outbound note',
|
||||
}),
|
||||
);
|
||||
expect(
|
||||
(result as any).timeline.filter((node: { system: string | null }) => node.system === 'OUTBOUND_RECORD'),
|
||||
).toHaveLength(expectedSystemNodes);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
@@ -58,6 +58,7 @@ export class PublicTraceService {
|
||||
outTime: Date;
|
||||
images: Array<{ fileKey: string; fileName: string; mimeType: string; id: bigint; size: bigint; width: number; height: number; sortOrder: number }>;
|
||||
} | null,
|
||||
showOutboundTimeline: boolean,
|
||||
) {
|
||||
const timeline = nodes.map((n) => ({
|
||||
nodeType: n.nodeType,
|
||||
@@ -71,7 +72,7 @@ export class PublicTraceService {
|
||||
|
||||
const outMedia = outbound?.images.map((image) => this.mapOutboundImage(image)) ?? [];
|
||||
|
||||
if (outbound) {
|
||||
if (showOutboundTimeline && outbound) {
|
||||
// 单件出库记录:不下发中文标题/说明,标记 system=OUTBOUND_RECORD 由 C 端按语言本地化
|
||||
timeline.push({
|
||||
nodeType: 'OUTBOUND',
|
||||
@@ -319,9 +320,14 @@ export class PublicTraceService {
|
||||
artist: artwork.artist,
|
||||
archiveNo: artwork.archiveNo,
|
||||
images: this.mapMedia(artwork.images),
|
||||
showOutboundTimeline: artwork.showOutboundTimeline,
|
||||
fields: this.buildFields(artwork.template.fields, artwork.dynamicFields),
|
||||
},
|
||||
timeline: this.buildTimeline(artwork.traceNodes, code.outbound ?? null),
|
||||
timeline: this.buildTimeline(
|
||||
artwork.traceNodes,
|
||||
code.outbound ?? null,
|
||||
artwork.showOutboundTimeline === true,
|
||||
),
|
||||
outbound: code.outbound
|
||||
? {
|
||||
outTime: code.outbound.outTime,
|
||||
|
||||
Reference in New Issue
Block a user