95 lines
2.4 KiB
TypeScript
95 lines
2.4 KiB
TypeScript
import {
|
|
BadRequestException,
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import type {
|
|
CreateWecomMessagePushRequest,
|
|
UpdateWecomMessagePushRequest,
|
|
} from '@dukang/shared-types';
|
|
import { HqAuthGuard } from '../../common/guards/hq-auth.guard';
|
|
import {
|
|
HqPermissionGuard,
|
|
RequireHqPermissions,
|
|
} from '../../common/guards/hq-permission.guard';
|
|
import { HqOperation } from '../../common/hq-operation/hq-operation.decorator';
|
|
import { HqOperationAction } from '../../common/hq-operation/hq-operation.constants';
|
|
import { AdminWecomMessagePushesService } from './admin-wecom-message-pushes.service';
|
|
|
|
@Controller('admin/wecom-message-pushes')
|
|
@UseGuards(HqAuthGuard, HqPermissionGuard)
|
|
@RequireHqPermissions('wecom_bots')
|
|
export class AdminWecomMessagePushesController {
|
|
constructor(private readonly service: AdminWecomMessagePushesService) {}
|
|
|
|
@Get()
|
|
list(
|
|
@Query('name') name?: string,
|
|
@Query('enabled') enabled?: string,
|
|
@Query('page') page?: string,
|
|
@Query('pageSize') pageSize?: string,
|
|
) {
|
|
return this.service.list({
|
|
name,
|
|
enabled,
|
|
page: page ? Number(page) : undefined,
|
|
pageSize: pageSize ? Number(pageSize) : undefined,
|
|
});
|
|
}
|
|
|
|
@Get(':id')
|
|
detail(@Param('id') id: string) {
|
|
return this.service.detail(BigInt(id));
|
|
}
|
|
|
|
@Post()
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_CREATE,
|
|
refType: 'WECOM_MESSAGE_PUSH',
|
|
includeBody: true,
|
|
})
|
|
create(@Body() body: CreateWecomMessagePushRequest) {
|
|
return this.service.create(body);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_UPDATE,
|
|
refType: 'WECOM_MESSAGE_PUSH',
|
|
refIdField: 'id',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('id') id: string, @Body() body: UpdateWecomMessagePushRequest) {
|
|
return this.service.update(BigInt(id), body);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_DELETE,
|
|
refType: 'WECOM_MESSAGE_PUSH',
|
|
refIdField: 'id',
|
|
})
|
|
remove(@Param('id') id: string) {
|
|
return this.service.remove(BigInt(id));
|
|
}
|
|
|
|
@Post(':id/test')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_TEST,
|
|
refType: 'WECOM_MESSAGE_PUSH',
|
|
refIdField: 'id',
|
|
})
|
|
async test(@Param('id') id: string) {
|
|
const result = await this.service.test(BigInt(id));
|
|
if (!result.ok) throw new BadRequestException(result.message);
|
|
return result;
|
|
}
|
|
}
|