import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { TimeoutUnknownDto } from './send-chain.contracts'; import { SendChainService } from './send-chain.service'; @ApiTags('send-chain') @Controller('admin/send') export class AdminSendChainController { constructor(private readonly sendChain: SendChainService) {} @Get('batch-tasks') listBatchTasks(@Query('tenantId') tenantId?: string, @Query('status') status?: string, @Query('keyword') keyword?: string, @Query('enterpriseKeyword') enterpriseKeyword?: string, @Query('applicationKeyword') applicationKeyword?: string, @Query('createdAtFrom') createdAtFrom?: string, @Query('createdAtTo') createdAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) { return page || pageSize ? this.sendChain.listBatchTasksPage({ tenantId, status, keyword, enterpriseKeyword, applicationKeyword, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize) }) : this.sendChain.listBatchTasks(tenantId, status); } @Get('batch-tasks/:id/messages') listBatchTaskMessages( @Param('id') taskId: string, @Query('phone') phone?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.sendChain.listAdminBatchTaskMessages(taskId, phone, Number(page), Number(pageSize)); } @Get('messages') listMessages( @Query('tenantId') tenantId?: string, @Query('applicationId') applicationId?: string, @Query('channelId') channelId?: string, @Query('taskId') taskId?: string, @Query('phoneNumber') phoneNumber?: string, @Query('status') status?: string, ) { return this.sendChain.listMessages({ tenantId, applicationId, channelId, taskId, phoneNumber, status }); } @Get('submit-records') listSubmitRecords(@Query('taskId') taskId?: string) { return this.sendChain.listSubmitRecords(taskId); } @Get('receipt-records') listReceiptRecords(@Query('taskId') taskId?: string) { return this.sendChain.listReceiptRecords(taskId); } @Get('uplink-messages') listUplinkMessages(@Query('tenantId') tenantId?: string, @Query('channelId') channelId?: string) { return this.sendChain.listUplinkMessages(tenantId, channelId); } @Post('batch-tasks/:id/enqueue') enqueueTask(@Param('id') taskId: string) { return this.sendChain.enqueueBatchTask(taskId); } @Post('batch-tasks/:id/terminate') terminateTask(@Param('id') taskId: string) { return this.sendChain.terminateBatchTask(taskId); } @Post('scheduled/dispatch-due') dispatchDueScheduledTasks() { return this.sendChain.dispatchDueScheduledTasks(); } @Post('timeouts/mark-unknown') markUnknownTimeout(@Body() body: TimeoutUnknownDto) { return this.sendChain.markUnknownTimeout(body); } }