fix: harden real backend workflows and channel connections

This commit is contained in:
hectorzhao
2026-07-06 17:54:53 +08:00
parent 8cca361441
commit b5132d7f4e
47 changed files with 2530 additions and 314 deletions
+7 -7
View File
@@ -110,15 +110,15 @@ export class SmsConfigService {
if (!query.includeConnections) {
return applications;
}
const tenantIds = [...new Set(applications.map((application) => application.tenantId))];
const applicationIds = applications.map((application) => application.id);
const connections = await this.prisma.cmppConnectionState.findMany({
where: { tenantId: { in: tenantIds } },
where: { applicationId: { in: applicationIds } },
include: { channel: true },
orderBy: { updatedAt: 'desc' },
take: 500,
});
return applications.map((application) => {
const appConnections = connections.filter((connection) => connection.tenantId === application.tenantId);
const appConnections = connections.filter((connection) => connection.applicationId === application.id);
const todayTotal = application.messageRecords.length;
const delivered = application.messageRecords.filter((message) => message.status === 'delivered').length;
return {
@@ -298,7 +298,7 @@ export class SmsConfigService {
throw new NotFoundException('Application not found');
}
const connections = await this.prisma.cmppConnectionState.findMany({
where: { tenantId: application.tenantId },
where: { applicationId },
include: { channel: true },
orderBy: { updatedAt: 'desc' },
take: 100,
@@ -351,13 +351,13 @@ export class SmsConfigService {
throw new NotFoundException('Application not found');
}
const connection = await this.prisma.cmppConnectionState.findFirst({
where: { tenantId: application.tenantId, connectionId },
where: { applicationId, connectionId },
});
if (!connection) {
throw new NotFoundException('Connection not found');
}
const updated = await this.prisma.cmppConnectionState.update({
where: { channelId_connectionId: { channelId: connection.channelId, connectionId } },
where: { id: connection.id },
data: {
status: 'disconnected',
currentConnections: 0,
@@ -742,7 +742,7 @@ function normalizeApplicationCmppStatus(connections: Array<{ status: string; cur
if (applicationStatus !== 'active') {
return 'inactive';
}
if (connections.some((connection) => ['online', 'connected', 'open'].includes(connection.status) && connection.currentConnections > 0)) {
if (connections.some((connection) => connection.status === 'connected' && connection.currentConnections > 0)) {
return 'connected';
}
if (connections.some((connection) => ['auth_failed', 'heartbeat_timeout', 'reconnecting'].includes(connection.status))) {