92 lines
2.3 KiB
TypeScript
92 lines
2.3 KiB
TypeScript
import {
|
|
Body,
|
|
Controller,
|
|
Delete,
|
|
Get,
|
|
Param,
|
|
Post,
|
|
Put,
|
|
Query,
|
|
UseGuards,
|
|
} from '@nestjs/common';
|
|
import type {
|
|
CreateWecomApiPluginRequest,
|
|
UpdateWecomApiPluginRequest,
|
|
} 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 { AdminWecomApiPluginsService } from './admin-wecom-api-plugins.service';
|
|
|
|
@Controller('admin/wecom-api-plugins')
|
|
@UseGuards(HqAuthGuard, HqPermissionGuard)
|
|
@RequireHqPermissions('wecom_bots')
|
|
export class AdminWecomApiPluginsController {
|
|
constructor(private readonly service: AdminWecomApiPluginsService) {}
|
|
|
|
@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_API_PLUGIN_CREATE,
|
|
refType: 'WECOM_API_PLUGIN',
|
|
includeBody: false,
|
|
})
|
|
create(@Body() body: CreateWecomApiPluginRequest) {
|
|
return this.service.create(body);
|
|
}
|
|
|
|
@Put(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_API_PLUGIN_UPDATE,
|
|
refType: 'WECOM_API_PLUGIN',
|
|
refIdField: 'id',
|
|
includeBody: false,
|
|
})
|
|
update(@Param('id') id: string, @Body() body: UpdateWecomApiPluginRequest) {
|
|
return this.service.update(BigInt(id), body);
|
|
}
|
|
|
|
@Delete(':id')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_API_PLUGIN_DELETE,
|
|
refType: 'WECOM_API_PLUGIN',
|
|
refIdField: 'id',
|
|
})
|
|
remove(@Param('id') id: string) {
|
|
return this.service.remove(BigInt(id));
|
|
}
|
|
|
|
@Post(':id/rotate-key')
|
|
@HqOperation({
|
|
action: HqOperationAction.WECOM_API_PLUGIN_ROTATE_KEY,
|
|
refType: 'WECOM_API_PLUGIN',
|
|
refIdField: 'id',
|
|
})
|
|
rotateKey(@Param('id') id: string) {
|
|
return this.service.rotateKey(BigInt(id));
|
|
}
|
|
}
|