fix: harden dependencies and downstream delivery

This commit is contained in:
hectorzhao
2026-07-15 12:05:24 +08:00
parent 9bbfb72be6
commit a758672436
17 changed files with 418 additions and 57 deletions
+6 -1
View File
@@ -105,7 +105,12 @@ describe('TenantsService', () => {
}));
expect(prisma.accountTransaction.groupBy).toHaveBeenCalledWith(expect.objectContaining({
by: ['tenantId'],
where: expect.objectContaining({ transactionType: 'refunded' }),
where: expect.objectContaining({
OR: [
{ transactionType: 'refunded' },
{ transactionType: 'released', relatedType: 'sms_message_record' },
],
}),
_sum: { amountCents: true },
}));
});
+11 -1
View File
@@ -59,7 +59,7 @@ export class TenantsService {
}),
this.prisma.accountTransaction.groupBy({
by: ['tenantId'],
where: { transactionType: 'refunded', createdAt: { gte: sinceToday } },
where: returnedTransactionWhere(sinceToday),
_sum: { amountCents: true },
}),
]);
@@ -201,6 +201,16 @@ function startOfToday() {
return date;
}
function returnedTransactionWhere(since: Date): Prisma.AccountTransactionWhereInput {
return {
createdAt: { gte: since },
OR: [
{ transactionType: 'refunded' },
{ transactionType: 'released', relatedType: 'sms_message_record' },
],
};
}
function generateTenantCode(data: CreateTenantDto) {
const source = data.creditCode?.trim() || data.name.trim();
const normalized = source.replace(/[^\da-zA-Z]/g, '').toLowerCase();