Files
certd/packages/ui/certd-server/src/controller/sys/authority/role-controller.ts
T

87 lines
2.0 KiB
TypeScript
Raw Normal View History

import { ALL, Body, Controller, Inject, Post, Provide, Query } from '@midwayjs/core';
2024-10-03 22:03:49 +08:00
import { CrudController } from '@certd/lib-server';
import { RoleService } from '../../../modules/sys/authority/service/role-service.js';
/**
* 系统用户
*/
@Provide()
@Controller('/api/sys/authority/role')
export class RoleController extends CrudController<RoleService> {
@Inject()
service: RoleService;
getService() {
return this.service;
}
@Post('/page', { description: 'sys:auth:role:view' })
async page(
@Body(ALL)
body
) {
return await super.page(body);
}
@Post('/list', { description: 'sys:auth:role:view' })
async list() {
const ret = await this.service.find({});
return this.ok(ret);
}
@Post('/add', { description: 'sys:auth:role:add' })
async add(
@Body(ALL)
bean
) {
return await super.add(bean);
}
@Post('/update', { description: 'sys:auth:role:edit' })
async update(
@Body(ALL)
bean
) {
return await super.update(bean);
}
@Post('/delete', { description: 'sys:auth:role:remove' })
async delete(
@Query('id')
id: number
) {
2024-10-03 01:29:12 +08:00
if (id === 1) {
throw new Error('不能删除默认的管理员角色');
}
return await super.delete(id);
}
@Post('/getPermissionTree', { description: 'sys:auth:role:view' })
async getPermissionTree(
@Query('id')
id: number
) {
const ret = await this.service.getPermissionTreeByRoleId(id);
return this.ok(ret);
}
@Post('/getPermissionIds', { description: 'sys:auth:role:view' })
async getPermissionIds(
@Query('id')
id: number
) {
const ret = await this.service.getPermissionIdsByRoleId(id);
return this.ok(ret);
}
/**
* 给角色授予权限
2023-06-27 09:29:43 +08:00
* @param roleId
* @param permissionIds
*/
@Post('/authz', { description: 'sys:auth:role:edit' })
2024-11-30 22:35:26 +08:00
async authz(@Body('roleId') roleId, @Body('permissionIds') permissionIds) {
await this.service.authz(roleId, permissionIds);
return this.ok(null);
}
}