Compare commits
No commits in common. "c825ff8a5f47127fc128a14fa9cb2f3822165c59" and "f0e3deb6c86476bd92a475f8ee112aa1cf3323ab" have entirely different histories.
c825ff8a5f
...
f0e3deb6c8
@ -1,4 +1,4 @@
|
|||||||
import { Prisma, PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
import bcrypt from 'bcryptjs';
|
import bcrypt from 'bcryptjs';
|
||||||
import { TENANT_ADMIN_ROLE_CODE } from '../src/common/constants.js';
|
import { TENANT_ADMIN_ROLE_CODE } from '../src/common/constants.js';
|
||||||
import { initTenant } from '../src/common/tenant-template.js';
|
import { initTenant } from '../src/common/tenant-template.js';
|
||||||
@ -115,7 +115,7 @@ interface SvcRecord {
|
|||||||
needCert: boolean;
|
needCert: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
function itemSnapshot(s: SvcRecord): Prisma.InputJsonObject {
|
function itemSnapshot(s: SvcRecord): Record<string, unknown> {
|
||||||
return {
|
return {
|
||||||
svcId: s.svcId,
|
svcId: s.svcId,
|
||||||
svcName: s.svcName,
|
svcName: s.svcName,
|
||||||
|
|||||||
@ -47,7 +47,6 @@ function makeService(
|
|||||||
planFindFirst?: ReturnType<typeof vi.fn>;
|
planFindFirst?: ReturnType<typeof vi.fn>;
|
||||||
planItemFindMany?: ReturnType<typeof vi.fn>;
|
planItemFindMany?: ReturnType<typeof vi.fn>;
|
||||||
elderFindFirst?: ReturnType<typeof vi.fn>;
|
elderFindFirst?: ReturnType<typeof vi.fn>;
|
||||||
elderFindMany?: ReturnType<typeof vi.fn>;
|
|
||||||
staffFindFirst?: ReturnType<typeof vi.fn>;
|
staffFindFirst?: ReturnType<typeof vi.fn>;
|
||||||
staffFindMany?: ReturnType<typeof vi.fn>;
|
staffFindMany?: ReturnType<typeof vi.fn>;
|
||||||
} = {},
|
} = {},
|
||||||
@ -61,7 +60,6 @@ function makeService(
|
|||||||
const planFindFirst = overrides.planFindFirst ?? vi.fn().mockResolvedValue(null);
|
const planFindFirst = overrides.planFindFirst ?? vi.fn().mockResolvedValue(null);
|
||||||
const planItemFindMany = overrides.planItemFindMany ?? vi.fn().mockResolvedValue([]);
|
const planItemFindMany = overrides.planItemFindMany ?? vi.fn().mockResolvedValue([]);
|
||||||
const elderFindFirst = overrides.elderFindFirst ?? vi.fn().mockResolvedValue(null);
|
const elderFindFirst = overrides.elderFindFirst ?? vi.fn().mockResolvedValue(null);
|
||||||
const elderFindMany = overrides.elderFindMany ?? vi.fn().mockResolvedValue([]);
|
|
||||||
const staffFindFirst = overrides.staffFindFirst ?? vi.fn().mockResolvedValue(null);
|
const staffFindFirst = overrides.staffFindFirst ?? vi.fn().mockResolvedValue(null);
|
||||||
const staffFindMany = overrides.staffFindMany ?? vi.fn().mockResolvedValue([]);
|
const staffFindMany = overrides.staffFindMany ?? vi.fn().mockResolvedValue([]);
|
||||||
|
|
||||||
@ -76,7 +74,7 @@ function makeService(
|
|||||||
},
|
},
|
||||||
plan: { findUnique: planFindUnique, findFirst: planFindFirst },
|
plan: { findUnique: planFindUnique, findFirst: planFindFirst },
|
||||||
planItem: { findMany: planItemFindMany },
|
planItem: { findMany: planItemFindMany },
|
||||||
elder: { findFirst: elderFindFirst, findMany: elderFindMany },
|
elder: { findFirst: elderFindFirst },
|
||||||
staff: { findFirst: staffFindFirst, findMany: staffFindMany },
|
staff: { findFirst: staffFindFirst, findMany: staffFindMany },
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -92,7 +90,6 @@ function makeService(
|
|||||||
planFindFirst,
|
planFindFirst,
|
||||||
planItemFindMany,
|
planItemFindMany,
|
||||||
elderFindFirst,
|
elderFindFirst,
|
||||||
elderFindMany,
|
|
||||||
staffFindFirst,
|
staffFindFirst,
|
||||||
staffFindMany,
|
staffFindMany,
|
||||||
};
|
};
|
||||||
@ -415,29 +412,3 @@ describe('OrderService.list', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('OrderService.today', () => {
|
|
||||||
it('返回当日工单并附加 elderName', async () => {
|
|
||||||
const staffFindFirst = vi.fn().mockResolvedValue({ id: 's1', userId: 'u1' });
|
|
||||||
const orderFindMany = vi.fn().mockResolvedValue([makeOrder({ assigneeId: 's1', elderId: 'e1' })]);
|
|
||||||
const elderFindMany = vi.fn().mockResolvedValue([{ id: 'e1', name: '张三' }]);
|
|
||||||
const { service } = makeService({ staffFindFirst, orderFindMany, elderFindMany });
|
|
||||||
|
|
||||||
const res = await runWithRequestContext(ctx, () => service.today({}));
|
|
||||||
|
|
||||||
expect(res).toHaveLength(1);
|
|
||||||
expect(res[0].elderName).toBe('张三');
|
|
||||||
expect(elderFindMany).toHaveBeenCalledWith({ where: { id: { in: ['e1'] } } });
|
|
||||||
});
|
|
||||||
|
|
||||||
it('无对应老人时 elderName 为 null', async () => {
|
|
||||||
const staffFindFirst = vi.fn().mockResolvedValue({ id: 's1', userId: 'u1' });
|
|
||||||
const orderFindMany = vi.fn().mockResolvedValue([makeOrder({ assigneeId: 's1', elderId: 'e-missing' })]);
|
|
||||||
const elderFindMany = vi.fn().mockResolvedValue([]);
|
|
||||||
const { service } = makeService({ staffFindFirst, orderFindMany, elderFindMany });
|
|
||||||
|
|
||||||
const res = await runWithRequestContext(ctx, () => service.today({}));
|
|
||||||
|
|
||||||
expect(res[0].elderName).toBeNull();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|||||||
@ -208,16 +208,10 @@ export class OrderService {
|
|||||||
const staff = await this.prisma.client.staff.findFirst({ where: { userId: ctx.userId } });
|
const staff = await this.prisma.client.staff.findFirst({ where: { userId: ctx.userId } });
|
||||||
if (!staff) return [];
|
if (!staff) return [];
|
||||||
const serviceDate = q.serviceDate ? toDateOnly(q.serviceDate) : toDateOnly(todayStr());
|
const serviceDate = q.serviceDate ? toDateOnly(q.serviceDate) : toDateOnly(todayStr());
|
||||||
const orders = await this.prisma.client.order.findMany({
|
return this.prisma.client.order.findMany({
|
||||||
where: { assigneeId: staff.id, serviceDate },
|
where: { assigneeId: staff.id, serviceDate },
|
||||||
orderBy: { timeSlotStart: 'asc' },
|
orderBy: { timeSlotStart: 'asc' },
|
||||||
});
|
});
|
||||||
const elderIds = [...new Set(orders.map((o) => o.elderId).filter((id): id is string => !!id))];
|
|
||||||
const elders = elderIds.length
|
|
||||||
? await this.prisma.client.elder.findMany({ where: { id: { in: elderIds } } })
|
|
||||||
: [];
|
|
||||||
const nameMap = new Map(elders.map((e) => [e.id, e.name]));
|
|
||||||
return orders.map((order) => ({ ...order, elderName: nameMap.get(order.elderId) ?? null }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 批量推荐:只读,不自动派。权重:同资质→历史服务过→距离近→负荷低(距离/负荷留 TODO)。 */
|
/** 批量推荐:只读,不自动派。权重:同资质→历史服务过→距离近→负荷低(距离/负荷留 TODO)。 */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user