70 lines
2.0 KiB
TypeScript
70 lines
2.0 KiB
TypeScript
import {
|
|
BadRequestException,
|
|
Body,
|
|
Controller,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import type { UpdateWecomPushTemplateRequest } 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 { WecomMessagePushService } from '../../integrations/wecom/wecom-message-push.service';
|
|
|
|
@Controller('admin/wecom-push-templates')
|
|
@UseGuards(HqAuthGuard, HqPermissionGuard)
|
|
@RequireHqPermissions('wecom_bots')
|
|
export class AdminWecomPushTemplatesController {
|
|
constructor(private readonly wecomPush: WecomMessagePushService) {}
|
|
|
|
@Get()
|
|
list() {
|
|
return this.wecomPush.listTemplates();
|
|
}
|
|
|
|
@Get(':eventKey')
|
|
detail(@Param('eventKey') eventKey: string) {
|
|
return this.wecomPush.getTemplate(eventKey);
|
|
}
|
|
|
|
@Put(':eventKey')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_UPDATE,
|
|
refType: 'WECOM_PUSH_TEMPLATE',
|
|
refIdField: 'eventKey',
|
|
includeBody: true,
|
|
})
|
|
update(@Param('eventKey') eventKey: string, @Body() body: UpdateWecomPushTemplateRequest) {
|
|
return this.wecomPush.updateTemplate(eventKey, body);
|
|
}
|
|
|
|
@Post(':eventKey/reset')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_UPDATE,
|
|
refType: 'WECOM_PUSH_TEMPLATE',
|
|
refIdField: 'eventKey',
|
|
})
|
|
reset(@Param('eventKey') eventKey: string) {
|
|
return this.wecomPush.resetTemplate(eventKey);
|
|
}
|
|
|
|
@Post(':eventKey/test')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_MESSAGE_PUSH_TEST,
|
|
refType: 'WECOM_PUSH_TEMPLATE',
|
|
refIdField: 'eventKey',
|
|
})
|
|
async test(@Param('eventKey') eventKey: string) {
|
|
const result = await this.wecomPush.testTemplate(eventKey);
|
|
if (!result.ok) throw new BadRequestException(result.message);
|
|
return result;
|
|
}
|
|
}
|