fix: harden real backend admin workflows and ui
This commit is contained in:
@@ -23,10 +23,11 @@ export class AdminOperationsController {
|
||||
@Query('applicationId') applicationId?: string,
|
||||
@Query('channelId') channelId?: string,
|
||||
@Query('taskId') taskId?: string,
|
||||
@Query('messageId') messageId?: string,
|
||||
@Query('phoneNumber') phoneNumber?: string,
|
||||
@Query('status') status?: string,
|
||||
) {
|
||||
return this.operations.listMessages({ tenantId, applicationId, channelId, taskId, phoneNumber, status });
|
||||
return this.operations.listMessages({ tenantId, applicationId, channelId, taskId, messageId, phoneNumber, status });
|
||||
}
|
||||
|
||||
@Get('uplink-messages')
|
||||
|
||||
@@ -14,8 +14,20 @@ export class ClientOperationsController {
|
||||
}
|
||||
|
||||
@Get('batch-tasks/:id/messages')
|
||||
listTaskMessages(@Param('id') taskId: string, @Query('phoneNumber') phoneNumber?: string) {
|
||||
return this.operations.listMessages({ taskId, phoneNumber });
|
||||
listTaskMessages(@TenantId() tenantId: string | undefined, @Param('id') taskId: string, @Query('phoneNumber') phoneNumber?: string) {
|
||||
return this.operations.listMessages({ tenantId, taskId, phoneNumber });
|
||||
}
|
||||
|
||||
@Get('messages')
|
||||
listMessages(
|
||||
@TenantId() tenantId?: string,
|
||||
@Query('applicationId') applicationId?: string,
|
||||
@Query('taskId') taskId?: string,
|
||||
@Query('messageId') messageId?: string,
|
||||
@Query('phoneNumber') phoneNumber?: string,
|
||||
@Query('status') status?: string,
|
||||
) {
|
||||
return this.operations.listMessages({ tenantId, applicationId, taskId, messageId, phoneNumber, status });
|
||||
}
|
||||
|
||||
@Get('uplink-messages')
|
||||
|
||||
@@ -71,6 +71,7 @@ describe('OperationsService', () => {
|
||||
applicationId: 'app-1',
|
||||
channelId: 'channel-1',
|
||||
taskId: 'task-1',
|
||||
messageId: 'MSG-1',
|
||||
phoneNumber: '13800000001',
|
||||
status: 'delivered',
|
||||
});
|
||||
@@ -81,15 +82,30 @@ describe('OperationsService', () => {
|
||||
applicationId: 'app-1',
|
||||
channelId: 'channel-1',
|
||||
batchTaskId: 'task-1',
|
||||
messageId: 'MSG-1',
|
||||
phoneNumber: '13800000001',
|
||||
status: 'delivered',
|
||||
},
|
||||
include: { submitRecords: true, receiptRecords: true },
|
||||
include: { tenant: true, application: true, channel: true, submitRecords: true, receiptRecords: true },
|
||||
orderBy: { queuedAt: 'desc' },
|
||||
take: 500,
|
||||
});
|
||||
});
|
||||
|
||||
it('returns uplink messages with tenant and channel display data', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new OperationsService(prisma as never);
|
||||
|
||||
await service.listUplinkMessages({ tenantId: 'tenant-1', channelId: 'channel-1' });
|
||||
|
||||
expect(prisma.smsUplinkMessage.findMany).toHaveBeenCalledWith({
|
||||
where: { tenantId: 'tenant-1', channelId: 'channel-1' },
|
||||
include: { tenant: true, channel: true },
|
||||
orderBy: { receivedAt: 'desc' },
|
||||
take: 500,
|
||||
});
|
||||
});
|
||||
|
||||
it('builds dashboard and statistics aggregates', async () => {
|
||||
const prisma = createPrismaMock();
|
||||
const service = new OperationsService(prisma as never);
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface MessageQuery {
|
||||
applicationId?: string;
|
||||
channelId?: string;
|
||||
taskId?: string;
|
||||
messageId?: string;
|
||||
phoneNumber?: string;
|
||||
status?: string;
|
||||
}
|
||||
@@ -42,7 +43,7 @@ export class OperationsService {
|
||||
listMessages(query: MessageQuery) {
|
||||
return this.prisma.smsMessageRecord.findMany({
|
||||
where: messageWhere(query),
|
||||
include: { submitRecords: true, receiptRecords: true },
|
||||
include: { tenant: true, application: true, channel: true, submitRecords: true, receiptRecords: true },
|
||||
orderBy: { queuedAt: 'desc' },
|
||||
take: 500,
|
||||
});
|
||||
@@ -51,6 +52,7 @@ export class OperationsService {
|
||||
listUplinkMessages(query: { tenantId?: string; channelId?: string }) {
|
||||
return this.prisma.smsUplinkMessage.findMany({
|
||||
where: { tenantId: query.tenantId, channelId: query.channelId },
|
||||
include: { tenant: true, channel: true },
|
||||
orderBy: { receivedAt: 'desc' },
|
||||
take: 500,
|
||||
});
|
||||
@@ -352,6 +354,7 @@ function messageWhere(query: MessageQuery): Prisma.SmsMessageRecordWhereInput {
|
||||
applicationId: query.applicationId,
|
||||
channelId: query.channelId,
|
||||
batchTaskId: query.taskId,
|
||||
messageId: query.messageId,
|
||||
phoneNumber: query.phoneNumber,
|
||||
status: query.status,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user