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