diff --git a/src/abnormal/abnormal.service.spec.ts b/src/abnormal/abnormal.service.spec.ts index a9133bd..60b7c9b 100644 --- a/src/abnormal/abnormal.service.spec.ts +++ b/src/abnormal/abnormal.service.spec.ts @@ -176,8 +176,11 @@ describe('AbnormalService', () => { }); it('list 按 abnormal_type/notify_status/handle_status/老人 筛选', async () => { - const recordAbnormalFindMany = vi.fn().mockResolvedValue([{ id: 'a1' }]); - const recordAbnormalCount = vi.fn().mockResolvedValue(1); + const recordAbnormalFindMany = vi.fn().mockResolvedValue([ + { id: 'a1', visitLat: { toString: () => '25.010000' }, visitLng: { toString: () => '102.700000' } }, + { id: 'a2', visitLat: null, visitLng: null }, + ]); + const recordAbnormalCount = vi.fn().mockResolvedValue(2); const { service } = makeService({ recordAbnormalFindMany, recordAbnormalCount }); const res = await runWithRequestContext(ctx, () => @@ -199,6 +202,15 @@ describe('AbnormalService', () => { take: 20, }); expect(recordAbnormalCount).toHaveBeenCalledWith({ where }); - expect(res).toEqual({ list: [{ id: 'a1' }], total: 1, page: 1, pageSize: 20 }); + // Decimal → string(null 保持 null)。 + expect(res).toEqual({ + list: [ + { id: 'a1', visitLat: '25.010000', visitLng: '102.700000' }, + { id: 'a2', visitLat: null, visitLng: null }, + ], + total: 2, + page: 1, + pageSize: 20, + }); }); }); diff --git a/src/abnormal/abnormal.service.ts b/src/abnormal/abnormal.service.ts index 7bc30c5..55a52de 100644 --- a/src/abnormal/abnormal.service.ts +++ b/src/abnormal/abnormal.service.ts @@ -87,7 +87,17 @@ export class AbnormalService { }), this.prisma.client.recordAbnormal.count({ where }), ]); - return { list, total, page: q.page, pageSize: q.pageSize }; + // Prisma Decimal(visit_lat/visit_lng)经 TransformInterceptor 不会转字符串,会泄漏为 {s,e,d};显式序列化。 + return { + list: list.map((r) => ({ + ...r, + visitLat: r.visitLat != null ? r.visitLat.toString() : null, + visitLng: r.visitLng != null ? r.visitLng.toString() : null, + })), + total, + page: q.page, + pageSize: q.pageSize, + }; } /** 扑空证据必留:到访时间、定位(经纬)、原因、关联工单(3003)。 */