Files
lislgosms/api/src/send-chain/client-send-chain.controller.ts
T

54 lines
2.7 KiB
TypeScript

import { Body, Controller, Get, Param, Post, Query, UsePipes } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { CurrentTenantId } from '../auth/current-tenant-id.decorator';
import { CurrentSessionUserId } from '../auth/current-session-user.decorator';
import { ClientBatchTaskDto, ClientImportConfirmDto, ClientImportPreviewDto } from '../common/client-write.dto';
import { strictValidationPipe } from '../common/strict-validation.pipe';
import { SendChainService } from './send-chain.service';
@ApiTags('client-send-chain')
@Controller('client/send')
export class ClientSendChainController {
constructor(private readonly sendChain: SendChainService) {}
@Post('batch-tasks')
@UsePipes(strictValidationPipe)
createBatchTask(@CurrentTenantId() tenantId: string, @CurrentSessionUserId() createdById: string | undefined, @Body() body: ClientBatchTaskDto) {
return this.sendChain.createBatchTask({ ...body, tenantId, sourceType: 'client', createdById });
}
@Post('imports/preview')
@UsePipes(strictValidationPipe)
previewImport(@CurrentTenantId() tenantId: string, @Body() body: ClientImportPreviewDto) {
return this.sendChain.previewImport({ ...body, tenantId });
}
@Post('imports/confirm')
@UsePipes(strictValidationPipe)
confirmImport(@CurrentTenantId() tenantId: string, @CurrentSessionUserId() createdById: string | undefined, @Body() body: ClientImportConfirmDto) {
return this.sendChain.confirmImport({ ...body, tenantId, sourceType: 'client', createdById });
}
@Get('batch-tasks')
listBatchTasks(@CurrentTenantId() tenantId: string, @Query('status') status?: string, @Query('keyword') keyword?: 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, sourceType: 'client', keyword, applicationKeyword, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize) })
: this.sendChain.listBatchTasks(tenantId, status, 'client');
}
@Get('batch-tasks/:id')
getBatchTask(@CurrentTenantId() tenantId: string, @Param('id') taskId: string) {
return this.sendChain.getBatchTask(taskId, tenantId, 'client');
}
@Get('batch-tasks/:id/messages')
listTaskMessages(@CurrentTenantId() tenantId: string, @Param('id') taskId: string) {
return this.sendChain.listClientTaskMessages(taskId, tenantId);
}
@Post('batch-tasks/:id/cancel')
cancelBatchTask(@CurrentTenantId() tenantId: string, @Param('id') taskId: string) {
return this.sendChain.cancelBatchTask(taskId, tenantId, 'client');
}
}