mirror of
https://github.com/dadosfera/maestro.git
synced 2026-11-14 23:59:07 +00:00
FEAT: new routes do add or remove permisisons from role
This commit is contained in:
@@ -1,12 +1,15 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Permission } from 'src/modules/permissions/dto/entities';
|
||||
import { UserWithoutRoles } from 'src/modules/users/dtos/entities';
|
||||
export class Role {
|
||||
@ApiPropertyOptional({ type: [Permission] })
|
||||
permissions: Permission[];
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiPropertyOptional({ type: () => [Permission] })
|
||||
permissions: Permission[];
|
||||
@ApiPropertyOptional({ type: () => [UserWithoutRoles] })
|
||||
users: UserWithoutRoles[];
|
||||
@ApiProperty()
|
||||
createdAt: string;
|
||||
@ApiProperty()
|
||||
@@ -39,6 +42,28 @@ export class CreateRoleReq {
|
||||
description: string;
|
||||
}
|
||||
export class CreateRoleRes {
|
||||
@ApiProperty({ type: [Role] })
|
||||
roles: Role[];
|
||||
@ApiProperty()
|
||||
role: Role;
|
||||
}
|
||||
|
||||
export class AssignPermissionsToRoleReq {
|
||||
@ApiProperty()
|
||||
roleId: string;
|
||||
@ApiProperty()
|
||||
permissionIds: string[];
|
||||
}
|
||||
export class AssignPermissionsToRoleRes {
|
||||
@ApiProperty()
|
||||
role: Role;
|
||||
}
|
||||
|
||||
export class UnassignPermissionsToRoleReq {
|
||||
@ApiProperty()
|
||||
roleId: string;
|
||||
@ApiProperty()
|
||||
permissionIds: string[];
|
||||
}
|
||||
export class UnassignPermissionsToRoleRes {
|
||||
@ApiProperty()
|
||||
role: Role;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
Inject,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ApiResponse, ApiTags } from '@nestjs/swagger';
|
||||
@@ -13,10 +14,14 @@ import { User } from 'src/authentication/user.decorator';
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
import { RolesService } from './roles.service';
|
||||
import {
|
||||
AssignPermissionsToRoleReq,
|
||||
AssignPermissionsToRoleRes,
|
||||
CreateRoleReq,
|
||||
CreateRoleRes,
|
||||
GetRolesByCustomerReq,
|
||||
GetRolesByCustomerRes,
|
||||
UnassignPermissionsToRoleReq,
|
||||
UnassignPermissionsToRoleRes,
|
||||
} from './dto/entities';
|
||||
|
||||
@ApiTags('Roles')
|
||||
@@ -50,4 +55,21 @@ export class RolesController {
|
||||
this.logger.info('deleteRole', { user });
|
||||
return await this.rolesService.removeRole(id);
|
||||
}
|
||||
@Put('permissions')
|
||||
@ApiResponse({ type: AssignPermissionsToRoleRes })
|
||||
async assignPermissionsToRole(
|
||||
@User() user,
|
||||
@Body() body: AssignPermissionsToRoleReq,
|
||||
) {
|
||||
this.logger.info('assignPermissionsToRole', { user });
|
||||
}
|
||||
|
||||
@Delete('permissions')
|
||||
@ApiResponse({ type: UnassignPermissionsToRoleRes })
|
||||
async unassignPermissionsToRole(
|
||||
@User() user,
|
||||
@Body() body: UnassignPermissionsToRoleReq,
|
||||
) {
|
||||
this.logger.info('unassignPermissionsToRole', { user });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,6 +40,28 @@ export class User {
|
||||
@ApiProperty()
|
||||
updatedAt: string;
|
||||
}
|
||||
export class UserWithoutRoles {
|
||||
@ApiProperty()
|
||||
id: string;
|
||||
@ApiProperty()
|
||||
name: string;
|
||||
@ApiProperty()
|
||||
email: string;
|
||||
@ApiProperty()
|
||||
jobTitle: string;
|
||||
@ApiProperty()
|
||||
department: string;
|
||||
@ApiProperty()
|
||||
hierarchy: number;
|
||||
@ApiProperty()
|
||||
customer: Customer;
|
||||
@ApiProperty()
|
||||
mfaStatus: string;
|
||||
@ApiProperty()
|
||||
createdAt: string;
|
||||
@ApiProperty()
|
||||
updatedAt: string;
|
||||
}
|
||||
export class UserByCustomer {
|
||||
@ApiProperty({ type: [Role] })
|
||||
roles: Role[];
|
||||
|
||||
Reference in New Issue
Block a user