2023-01-29 15:26:58 +08:00
|
|
|
import {
|
|
|
|
|
ALL,
|
|
|
|
|
Body,
|
|
|
|
|
Controller,
|
|
|
|
|
Inject,
|
|
|
|
|
Post,
|
|
|
|
|
Provide,
|
|
|
|
|
Query,
|
2024-07-15 00:30:33 +08:00
|
|
|
} from '@midwayjs/core';
|
|
|
|
|
import { CrudController } from '../../../basic/crud-controller.js';
|
|
|
|
|
import { RoleService } from '../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;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/page', { summary: 'sys:auth:role:view' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async page(
|
|
|
|
|
@Body(ALL)
|
|
|
|
|
body
|
|
|
|
|
) {
|
|
|
|
|
return await super.page(body);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/list', { summary: 'sys:auth:role:view' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async list() {
|
|
|
|
|
const ret = await this.service.find({});
|
|
|
|
|
return this.ok(ret);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/add', { summary: 'sys:auth:role:add' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async add(
|
|
|
|
|
@Body(ALL)
|
|
|
|
|
bean
|
|
|
|
|
) {
|
|
|
|
|
return await super.add(bean);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/update', { summary: 'sys:auth:role:edit' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async update(
|
|
|
|
|
@Body(ALL)
|
|
|
|
|
bean
|
|
|
|
|
) {
|
|
|
|
|
return await super.update(bean);
|
|
|
|
|
}
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/delete', { summary: 'sys:auth:role:remove' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async delete(
|
|
|
|
|
@Query('id')
|
|
|
|
|
id
|
|
|
|
|
) {
|
|
|
|
|
return await super.delete(id);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/getPermissionTree', { summary: 'sys:auth:role:view' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async getPermissionTree(
|
|
|
|
|
@Query('id')
|
|
|
|
|
id
|
|
|
|
|
) {
|
|
|
|
|
const ret = await this.service.getPermissionTreeByRoleId(id);
|
|
|
|
|
return this.ok(ret);
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/getPermissionIds', { summary: 'sys:auth:role:view' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async getPermissionIds(
|
|
|
|
|
@Query('id')
|
|
|
|
|
id
|
|
|
|
|
) {
|
|
|
|
|
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
|
|
|
*/
|
2023-06-27 09:29:43 +08:00
|
|
|
@Post('/authz', { summary: 'sys:auth:role:edit' })
|
2023-01-29 15:26:58 +08:00
|
|
|
async authz(
|
|
|
|
|
@Body('roleId')
|
|
|
|
|
roleId,
|
|
|
|
|
@Body('permissionIds')
|
|
|
|
|
permissionIds
|
|
|
|
|
) {
|
|
|
|
|
await this.service.authz(roleId, permissionIds);
|
|
|
|
|
return this.ok(null);
|
|
|
|
|
}
|
|
|
|
|
}
|