56 lines
2.3 KiB
TypeScript
56 lines
2.3 KiB
TypeScript
import { BadRequestException, Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
|
|
import { ApiTags } from '@nestjs/swagger';
|
|
import { TenantId } from '../common/tenant-id.decorator';
|
|
import { ConfirmImportDto, CreateBatchTaskDto, ImportPreviewDto } from './send-chain.contracts';
|
|
import { SendChainService } from './send-chain.service';
|
|
|
|
@ApiTags('client-send-chain')
|
|
@Controller('client/send')
|
|
export class ClientSendChainController {
|
|
constructor(private readonly sendChain: SendChainService) {}
|
|
|
|
@Post('batch-tasks')
|
|
createBatchTask(@Body() body: CreateBatchTaskDto) {
|
|
return this.sendChain.createBatchTask(body);
|
|
}
|
|
|
|
@Post('imports/preview')
|
|
previewImport(@Body() body: ImportPreviewDto) {
|
|
return this.sendChain.previewImport(body);
|
|
}
|
|
|
|
@Post('imports/confirm')
|
|
confirmImport(@Body() body: ConfirmImportDto) {
|
|
return this.sendChain.confirmImport(body);
|
|
}
|
|
|
|
@Get('batch-tasks')
|
|
listBatchTasks(@TenantId() 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: requireTenantId(tenantId), status, sourceType: 'client', keyword, applicationKeyword, createdAtFrom, createdAtTo, page: Number(page), pageSize: Number(pageSize) })
|
|
: this.sendChain.listBatchTasks(requireTenantId(tenantId), status, 'client');
|
|
}
|
|
|
|
@Get('batch-tasks/:id')
|
|
getBatchTask(@TenantId() tenantId: string | undefined, @Param('id') taskId: string) {
|
|
return this.sendChain.getBatchTask(taskId, requireTenantId(tenantId), 'client');
|
|
}
|
|
|
|
@Get('batch-tasks/:id/messages')
|
|
listTaskMessages(@TenantId() tenantId: string | undefined, @Param('id') taskId: string) {
|
|
return this.sendChain.listClientTaskMessages(taskId, requireTenantId(tenantId));
|
|
}
|
|
|
|
@Post('batch-tasks/:id/cancel')
|
|
cancelBatchTask(@TenantId() tenantId: string | undefined, @Param('id') taskId: string) {
|
|
return this.sendChain.cancelBatchTask(taskId, requireTenantId(tenantId), 'client');
|
|
}
|
|
}
|
|
|
|
function requireTenantId(tenantId?: string) {
|
|
if (!tenantId) {
|
|
throw new BadRequestException('Tenant context is required');
|
|
}
|
|
return tenantId;
|
|
}
|