feat: add access number routing and admin list improvements
This commit is contained in:
@@ -114,4 +114,23 @@ describe('TenantsService', () => {
|
||||
_sum: { amountCents: true },
|
||||
}));
|
||||
});
|
||||
|
||||
it('sorts management rows by today spend descending with a stable name tie-breaker', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
prisma.tenant.findMany.mockResolvedValue([
|
||||
{ id: 'tenant-1', name: '乙企业', code: 'T1', status: 'active', enterpriseCertifications: [] },
|
||||
{ id: 'tenant-2', name: '甲企业', code: 'T2', status: 'active', enterpriseCertifications: [] },
|
||||
{ id: 'tenant-3', name: '丙企业', code: 'T3', status: 'active', enterpriseCertifications: [] },
|
||||
]);
|
||||
prisma.smsMessageRecord.groupBy.mockResolvedValue([
|
||||
{ tenantId: 'tenant-1', _sum: { amountCents: 300 } },
|
||||
{ tenantId: 'tenant-2', _sum: { amountCents: 300 } },
|
||||
{ tenantId: 'tenant-3', _sum: { amountCents: 500 } },
|
||||
]);
|
||||
const service = new TenantsService(prisma as never);
|
||||
|
||||
const rows = await service.listManagementRows();
|
||||
|
||||
expect(rows.map((row) => row.id)).toEqual(['tenant-3', 'tenant-2', 'tenant-1']);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -71,7 +71,9 @@ export class TenantsService {
|
||||
account: accountsByTenant.get(tenant.id) ?? null,
|
||||
todaySpendCents: todaySpendByTenant.get(tenant.id) ?? 0,
|
||||
todayRefundCents: todayRefundByTenant.get(tenant.id) ?? 0,
|
||||
}));
|
||||
})).sort((left, right) => right.todaySpendCents - left.todaySpendCents
|
||||
|| left.name.localeCompare(right.name, 'zh-CN')
|
||||
|| left.id.localeCompare(right.id));
|
||||
}
|
||||
|
||||
get(id: string) {
|
||||
|
||||
Reference in New Issue
Block a user