fix: 修复出库追溯码默认加载

This commit is contained in:
Nixevol
2026-07-03 04:35:05 +08:00
parent 9eda1b722a
commit bc6a4e9cc2
5 changed files with 109 additions and 30 deletions
+20 -1
View File
@@ -9,6 +9,7 @@ import * as QRCode from 'qrcode';
import dayjs from 'dayjs';
import { ArtworkStatus, ErrorCode, JobType, QUEUE_NAMES, TraceCodeStatus } 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 { JobsService } from '../jobs/jobs.service';
@@ -28,6 +29,7 @@ export class TraceCodeService {
private readonly prisma: PrismaService,
private readonly jobs: JobsService,
private readonly config: ConfigService,
private readonly storage: StorageService,
@InjectQueue(QUEUE_NAMES.GEN_CODE) private readonly genQueue: Queue,
) {}
@@ -173,6 +175,11 @@ export class TraceCodeService {
artwork: { select: { id: true, title: true, archiveNo: true } },
batch: { select: { id: true, batchNo: true } },
group: { select: { id: true, name: true } },
proofs: {
where: { status: 'ONCHAIN' },
orderBy: [{ onchainAt: 'desc' }, { id: 'desc' }],
take: 1,
},
},
orderBy: { id: 'desc' },
skip: query.skip,
@@ -180,7 +187,19 @@ export class TraceCodeService {
}),
this.prisma.traceCode.count({ where }),
]);
return buildPage(list, total, query.page, query.pageSize);
return buildPage(
list.map((code) => {
const { proofs, ...rest } = code;
return {
...rest,
outImageUrl: code.outImage ? this.storage.getUrl(code.outImage) : null,
latestProof: proofs[0] ?? null,
};
}),
total,
query.page,
query.pageSize,
);
}
async getQrPng(id: bigint): Promise<Buffer> {