Files
lislgosms/api/src/channels/channels.controller.ts
T

211 lines
8.0 KiB
TypeScript

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('status') status?: string, @Query('channelId') channelId?: string, @Query('reportType') reportType?: string, @Query('keyword') keyword?: string, @Query('createdAtFrom') createdAtFrom?: string, @Query('createdAtTo') createdAtTo?: string, @Query('page') page?: string, @Query('pageSize') pageSize?: string) {
return page || pageSize || keyword || createdAtFrom || createdAtTo
? this.channels.listReportTasksPage({ tenantId, status, channelId, reportType, keyword, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize) })
: this.channels.listReportTasks(tenantId, status, channelId, reportType);
}
@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('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 || reportType || createdAtFrom || createdAtTo
? this.channels.listReportRecordsPage({ taskId, channelId, keyword, reportType, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize) })
: this.channels.listReportRecords(taskId, channelId);
}
}