Files
lislgosms/api/src/operations/client-operations.controller.ts
T

126 lines
3.8 KiB
TypeScript

import { Body, Controller, Get, Param, Post, Query, UsePipes } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';
import { CurrentSessionUserId } from '../auth/current-session-user.decorator';
import { CurrentTenantId } from '../auth/current-tenant-id.decorator';
import { OperationsService } from './operations.service';
import { strictValidationPipe } from '../common/strict-validation.pipe';
import { ClientSystemLogExportDto } from './client-operations.dto';
@ApiTags('client-operations')
@Controller('client/operations')
export class ClientOperationsController {
constructor(private readonly operations: OperationsService) {}
@Get('batch-tasks')
listBatchTasks(@CurrentTenantId() tenantId: string, @Query('status') status?: string) {
return this.operations.listClientBatchTasks({ tenantId, status });
}
@Get('batch-tasks/:id/messages')
listTaskMessages(
@CurrentTenantId() tenantId: string,
@Param('id') taskId: string,
@Query('phoneNumber') phoneNumber?: string,
) {
return this.operations.listClientMessages({ tenantId, taskId, phoneNumber });
}
@Get('messages')
listMessages(
@CurrentTenantId() tenantId: string,
@Query('applicationId') applicationId?: string,
@Query('taskId') taskId?: string,
@Query('messageId') messageId?: string,
@Query('phoneNumber') phoneNumber?: string,
@Query('status') status?: string,
@Query('contentKeyword') contentKeyword?: string,
@Query('queuedAtFrom') queuedAtFrom?: string,
@Query('queuedAtTo') queuedAtTo?: string,
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
) {
return this.operations.listClientMessagesPage({
tenantId,
applicationId,
taskId,
messageId,
phoneNumber,
status,
contentKeyword,
queuedAtFrom,
queuedAtTo,
page: Number(page),
pageSize: Number(pageSize),
});
}
@Get('uplink-messages')
listUplinkMessages(
@CurrentTenantId() tenantId: string,
@Query('channelId') channelId?: string,
@Query('applicationId') applicationId?: string,
@Query('phoneNumber') phoneNumber?: string,
@Query('keyword') keyword?: string,
@Query('startTime') startTime?: string,
@Query('endTime') endTime?: string,
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
) {
return page || pageSize
? this.operations.listUplinkMessagesPage(
{
tenantId,
applicationId,
phoneNumber,
keyword,
startTime,
endTime,
page: Number(page),
pageSize: Number(pageSize),
},
true,
)
: this.operations.listClientUplinkMessages({ tenantId, applicationId, phoneNumber, keyword, startTime, endTime });
}
@Get('dashboard')
dashboard(@CurrentTenantId() tenantId: string) {
return this.operations.clientDashboard({ tenantId });
}
@Get('system-logs')
systemLogs(
@CurrentTenantId() tenantId: string,
@Query('keyword') keyword?: string,
@Query('level') level?: string,
@Query('module') module?: string,
@Query('range') range?: string,
@Query('createdAtFrom') createdAtFrom?: string,
@Query('createdAtTo') createdAtTo?: string,
@Query('page') page?: string,
@Query('pageSize') pageSize?: string,
) {
return this.operations.systemLogs({
tenantId,
keyword,
level,
module,
range,
createdAtFrom,
createdAtTo,
page: Number(page),
pageSize: Number(pageSize),
});
}
@Post('system-logs/exports')
@UsePipes(strictValidationPipe)
exportSystemLogs(
@CurrentSessionUserId() userId: string | undefined,
@CurrentTenantId() tenantId: string,
@Body() body: ClientSystemLogExportDto,
) {
return this.operations.exportSystemLogs({ ...body, tenantId }, userId);
}
}