monorepo-microservice-rbac/apps/services/cert/authorize/src/app.controller.ts

71 lines
2.0 KiB
TypeScript
Raw Normal View History

2023-08-27 14:37:59 +08:00
import { Controller } from '@nestjs/common';
import { AppService } from './app.service';
import { EventPattern, MessagePattern } from '@nestjs/microservices';
import { RbacService } from './rbac/rbac.service';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
private readonly rbacService: RbacService,
) {}
@EventPattern({ cmd: 'cert.authorize' })
async authorize(payload) {
console.log('获取user的token进行payload权限的验证', payload);
return false;
}
@EventPattern({ cmd: 'cert.init.role.admin' })
async initRole() {
await this.rbacService.initSuperAdminRole();
await this.rbacService.initSuperAdminAccount();
}
@EventPattern({ cmd: 'cert.create.role' })
async createRole(payload) {
return await this.rbacService.createRole(payload);
}
@EventPattern({ cmd: 'cert.remove.role' })
async removeRole(payload) {
return await this.rbacService.removeRole(payload);
}
@EventPattern({ cmd: 'cert.find.role.all' })
async findAllRole() {
return await this.rbacService.findAllRole();
}
@EventPattern({ cmd: 'cert.init.permission.resource' })
async initPermission(payload) {
await this.rbacService.initPermission(payload);
}
@EventPattern({ cmd: 'cert.find.role.permission' })
async findRolePermission(payload) {
return await this.rbacService.findRolePermission(payload);
}
@EventPattern({ cmd: 'cert.update.role.permissions' })
async updateRolePermissions(payload) {
return await this.rbacService.updateRolePermissions(payload);
}
@EventPattern({ cmd: 'cert.update.role' })
async updateRole(payload) {
return await this.rbacService.updateRole(payload);
}
@EventPattern({ cmd: 'cert.find.all.user' })
async findAllUser() {
return await this.rbacService.findAllUser();
}
@EventPattern({ cmd: 'cert.role.authorize' })
async roleAuthorize({ user, url }) {
const allow = await this.rbacService.roleAuthorize(user, url);
return { allow };
}
}