import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common'; import { ApiTags } from '@nestjs/swagger'; import { RequireRecentAuthentication } from '../auth/require-recent-authentication.decorator'; import { CurrentSessionUserId } from '../auth/current-session-user.decorator'; import { DeleteTargetDto, DeletionGovernanceService } from '../deletion-governance/deletion-governance.service'; import { ChangeChannelStatusDto, CopyChannelDto, CreateChannelDto, CreateChannelGroupDto, CreateChannelGroupItemDto, CreateReceiptImportDto, CreateReportExportDto, CreateReportFieldDto, CreateReportMaterialDto, CreateReportTaskDto, ReplaceReportFieldsDto, ChangeReportTaskStatusesDto, CreateRouteRuleDto, TestChannelDto, UpsertConnectionStateDto, UpdateChannelDto, UpdateChannelGroupDto, } from './channels.contracts'; import { ChannelsService } from './channels.service'; @ApiTags('channels') @Controller('admin') export class ChannelsController { constructor( private readonly channels: ChannelsService, private readonly deletions: DeletionGovernanceService, ) {} @Get('channels') listChannels( @Query('keyword') keyword?: string, @Query('carrier') carrier?: string, @Query('status') status?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return page || pageSize ? this.channels.listChannelsPage({ keyword, carrier, status, page: Number(page), pageSize: Number(pageSize) }) : this.channels.listChannels(); } @Post('channels') @RequireRecentAuthentication() createChannel(@Body() body: CreateChannelDto) { return this.channels.createChannel(body); } @Put('channels/:id') @RequireRecentAuthentication() updateChannel(@Param('id') channelId: string, @Body() body: UpdateChannelDto) { return this.channels.updateChannel(channelId, body); } @Post('channels/:id/test') @RequireRecentAuthentication() testChannel(@Param('id') channelId: string, @Body() body: TestChannelDto) { return this.channels.testChannel(channelId, body); } @Post('channels/:id/status') @RequireRecentAuthentication() changeChannelStatus(@Param('id') channelId: string, @Body() body: ChangeChannelStatusDto) { return this.channels.changeChannelStatus(channelId, body); } @Post('channels/:id/copy') @RequireRecentAuthentication() copyChannel(@Param('id') channelId: string, @Body() body: CopyChannelDto) { return this.channels.copyChannel(channelId, body); } @Delete('channels/:id') @RequireRecentAuthentication() deleteChannel( @Param('id') channelId: string, @Body() body: DeleteTargetDto, @CurrentSessionUserId() operatorId?: string, ) { return this.deletions.delete('channel', channelId, { ...body, operatorId }); } @Get('channels/:id/metrics') listChannelMetrics(@Param('id') channelId: string) { return this.channels.listChannelMetrics(channelId); } @Get('channels/:id/link-logs') listLegacyChannelConnectionLogs(@Param('id') channelId: string) { return this.channels.listChannelConnectionLogs(channelId); } @Get('channels/:id/connection-logs') listChannelConnectionLogs(@Param('id') channelId: string) { return this.channels.listChannelConnectionLogs(channelId); } @Get('channels/:id/connections') listChannelConnections(@Param('id') channelId: string) { return this.channels.listChannelConnections(channelId); } @Get('tenants/:id/connections') listTenantConnections(@Param('id') tenantId: string) { return this.channels.listTenantConnections(tenantId); } @Post('gateway/connections') upsertConnectionState(@Body() body: UpsertConnectionStateDto) { return this.channels.upsertConnectionState(body); } @Get('channel-groups') listGroups() { return this.channels.listGroups(); } @Post('channel-groups') @RequireRecentAuthentication() createGroup(@Body() body: CreateChannelGroupDto) { return this.channels.createGroup(body); } @Put('channel-groups/:id') @RequireRecentAuthentication() updateGroup(@Param('id') groupId: string, @Body() body: UpdateChannelGroupDto) { return this.channels.updateGroup(groupId, body); } @Get('channel-groups/:id/deletion-impact') getGroupDeletionImpact(@Param('id') groupId: string) { return this.channels.getGroupDeletionImpact(groupId); } @Delete('channel-groups/:id') @RequireRecentAuthentication() deleteGroup(@Param('id') groupId: string) { return this.channels.deleteGroup(groupId); } @Post('channel-groups/items') @RequireRecentAuthentication() addGroupItem(@Body() body: CreateChannelGroupItemDto) { return this.channels.addGroupItem(body); } @Get('channel-route-rules') listRouteRules() { return this.channels.listRouteRules(); } @Post('channel-route-rules') @RequireRecentAuthentication() createRouteRule(@Body() body: CreateRouteRuleDto) { return this.channels.createRouteRule(body); } @Get('channel-report-fields') listReportFields(@Query('channelId') channelId?: string) { return this.channels.listReportFields(channelId); } @Post('channel-report-fields') createReportField(@Body() body: CreateReportFieldDto) { return this.channels.createReportField(body); } @Put('channels/:channelId/report-fields/:reportType') @RequireRecentAuthentication() replaceReportFields( @Param('channelId') channelId: string, @Param('reportType') reportType: 'signature' | 'drainage', @Body() body: ReplaceReportFieldsDto, ) { return this.channels.replaceReportFields(channelId, reportType, body); } @Get('signature-report-materials') listReportMaterials(@Query('signatureId') signatureId?: string, @Query('channelId') channelId?: string) { return this.channels.listReportMaterials(signatureId, channelId); } @Post('signature-report-materials') upsertReportMaterial(@Body() body: CreateReportMaterialDto) { return this.channels.upsertReportMaterial(body); } @Get('report-tasks') listReportTasks( @Query('tenantId') tenantId?: string, @Query('applicationId') applicationId?: string, @Query('status') status?: string, @Query('channelId') channelId?: string, @Query('reportType') reportType?: string, @Query('keyword') keyword?: string, @Query('carrier') carrier?: string, @Query('todaySendMin') todaySendMin?: string, @Query('todaySendMax') todaySendMax?: string, @Query('sort') sort?: string, @Query('createdAtFrom') createdAtFrom?: string, @Query('createdAtTo') createdAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return page || pageSize || keyword || applicationId || carrier || todaySendMin || todaySendMax || sort || createdAtFrom || createdAtTo ? this.channels.listReportTasksPage({ tenantId, applicationId, status, channelId, reportType, keyword, carrier, todaySendMin: Number(todaySendMin), todaySendMax: Number(todaySendMax), sort, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize), }) : this.channels.listReportTasks(tenantId, status, channelId, reportType); } @Get('report-details') listReportDetails( @Query('tenantId') tenantId?: string, @Query('applicationId') applicationId?: string, @Query('signatureId') signatureId?: string, @Query('channelId') channelId?: string, @Query('carrier') carrier?: string, @Query('status') status?: string, @Query('reportType') reportType?: string, @Query('keyword') keyword?: string, @Query('enterpriseKeyword') enterpriseKeyword?: string, @Query('applicationKeyword') applicationKeyword?: string, @Query('channelKeyword') channelKeyword?: string, @Query('objectKeyword') objectKeyword?: string, @Query('createdAtFrom') createdAtFrom?: string, @Query('createdAtTo') createdAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return this.channels.listReportDetailsPage({ tenantId, applicationId, signatureId, channelId, carrier, status, reportType, keyword, enterpriseKeyword, applicationKeyword, channelKeyword, objectKeyword, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize), }); } @Post('report-tasks/generate') createReportTask(@Body() body: CreateReportTaskDto) { return this.channels.createReportTask(body); } @Post('report-tasks/status-change') @RequireRecentAuthentication() changeReportTaskStatuses(@Body() body: ChangeReportTaskStatusesDto, @CurrentSessionUserId() operatorId?: string) { return this.channels.changeReportTaskStatuses({ ...body, operatorId }); } @Post('report-tasks/:id/export') createReportExport(@Param('id') taskId: string, @Body() body: CreateReportExportDto) { return this.channels.createReportExport(taskId, body); } @Post('report-tasks/:id/receipt-import') importReportReceipt(@Param('id') taskId: string, @Body() body: CreateReceiptImportDto) { return this.channels.importReportReceipt(taskId, body); } @Get('report-records') listReportRecords( @Query('taskId') taskId?: string, @Query('channelId') channelId?: string, @Query('batchNo') batchNo?: string, @Query('statusAfter') statusAfter?: string, @Query('action') action?: string, @Query('sourceEntry') sourceEntry?: string, @Query('operatorKeyword') operatorKeyword?: string, @Query('keyword') keyword?: string, @Query('reportType') reportType?: string, @Query('createdAtFrom') createdAtFrom?: string, @Query('createdAtTo') createdAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string, ) { return page || pageSize || keyword || batchNo || statusAfter || action || sourceEntry || operatorKeyword || reportType || createdAtFrom || createdAtTo ? this.channels.listReportRecordsPage({ taskId, channelId, batchNo, statusAfter, action, sourceEntry, operatorKeyword, keyword, reportType, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize), }) : this.channels.listReportRecords(taskId, channelId); } }