fix: remove truncated management totals
This commit is contained in:
@@ -331,19 +331,28 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
return this.getBatchTask(task.id);
|
||||
}
|
||||
|
||||
listBatchTasks(tenantId?: string, status?: string) {
|
||||
return this.prisma.smsBatchTask.findMany({
|
||||
async listBatchTasks(tenantId?: string, status?: string) {
|
||||
const tasks = await this.prisma.smsBatchTask.findMany({
|
||||
where: { tenantId, status },
|
||||
include: {
|
||||
tenant: true,
|
||||
application: true,
|
||||
template: true,
|
||||
apiRequests: true,
|
||||
messages: { include: { channel: true }, orderBy: { queuedAt: 'asc' }, take: 100000 },
|
||||
},
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 100,
|
||||
});
|
||||
const taskIds = tasks.map((task) => task.id);
|
||||
const messageStats = taskIds.length > 0 ? await this.prisma.smsMessageRecord.groupBy({
|
||||
by: ['batchTaskId', 'carrier', 'province', 'status'],
|
||||
where: { batchTaskId: { in: taskIds } },
|
||||
_count: { _all: true },
|
||||
_sum: { billingUnits: true },
|
||||
}) : [];
|
||||
return tasks.map((task) => ({
|
||||
...task,
|
||||
messageStats: messageStats.filter((item) => item.batchTaskId === task.id),
|
||||
}));
|
||||
}
|
||||
|
||||
getBatchTask(taskId: string) {
|
||||
@@ -378,7 +387,6 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
receiptRecords: { include: { channel: true }, orderBy: { createdAt: 'asc' } },
|
||||
},
|
||||
orderBy: { queuedAt: 'desc' },
|
||||
take: 500,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -386,7 +394,6 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
return this.prisma.smsSubmitRecord.findMany({
|
||||
where: { batchTaskId: taskId },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -394,7 +401,6 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
return this.prisma.smsReceiptRecord.findMany({
|
||||
where: { batchTaskId: taskId },
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -403,7 +409,6 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
where: { tenantId, channelId },
|
||||
include: { application: true, channel: true, messageRecord: { include: { application: true } } },
|
||||
orderBy: { receivedAt: 'desc' },
|
||||
take: 200,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -542,7 +547,6 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
const tasks = await this.prisma.smsBatchTask.findMany({
|
||||
where: { status: 'scheduled', scheduledAt: { lte: now } },
|
||||
orderBy: { scheduledAt: 'asc' },
|
||||
take: 100,
|
||||
});
|
||||
const results: Array<{ taskId: string; status: string; enqueued?: number; reason?: string }> = [];
|
||||
for (const task of tasks) {
|
||||
@@ -1812,7 +1816,6 @@ export class SendChainService implements OnModuleInit, OnModuleDestroy {
|
||||
const rules = await this.prisma.phoneCarrierRule.findMany({
|
||||
where: { status: 'active' },
|
||||
orderBy: [{ priority: 'asc' }, { createdAt: 'asc' }],
|
||||
take: 100,
|
||||
});
|
||||
for (const rule of rules) {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user