mirror of
https://github.com/dadosfera/maestro.git
synced 2026-09-30 17:19:08 +00:00
FIX: Update user accepting roleIds
This commit is contained in:
@@ -104,6 +104,8 @@ export class UpdateUserReq {
|
||||
department?: string;
|
||||
@ApiPropertyOptional()
|
||||
hierarchy?: number;
|
||||
@ApiPropertyOptional()
|
||||
roleNames?: string[];
|
||||
}
|
||||
|
||||
export class UpdateUserRes {
|
||||
|
||||
@@ -111,7 +111,7 @@ export class UsersController {
|
||||
@ApiOkResponse({ type: SetUserRolesRes })
|
||||
async setUserRoles(@User() user: RequestUser, @Body() body: SetUserRolesReq) {
|
||||
this.logger.info('createUser', { user });
|
||||
return await this.userService.setRoles(body);
|
||||
return await this.userService.setRoles(body, user.customer_id);
|
||||
}
|
||||
|
||||
@Put('role')
|
||||
@@ -143,6 +143,6 @@ export class UsersController {
|
||||
@Param('id') id: string,
|
||||
) {
|
||||
this.logger.info('updateUser', { user });
|
||||
return await this.userService.updateUser(body, id);
|
||||
return await this.userService.updateUser(body, id, user.customer_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,8 +85,11 @@ export class UsersService implements OnModuleInit {
|
||||
return { user };
|
||||
}
|
||||
|
||||
async updateUser(req: UpdateUserReq, id: string) {
|
||||
const { department, hierarchy, jobTitle, name } = req;
|
||||
async updateUser(req: UpdateUserReq, id: string, customerId: string) {
|
||||
const { department, hierarchy, jobTitle, name, roleNames } = req;
|
||||
if (roleNames) {
|
||||
await this.setRoles({ roleNames, userId: id }, customerId);
|
||||
}
|
||||
const { user } = await lastValueFrom(
|
||||
this.usersClientService.UserUpdate({
|
||||
name,
|
||||
@@ -106,7 +109,7 @@ export class UsersService implements OnModuleInit {
|
||||
return { user };
|
||||
}
|
||||
|
||||
async setRoles(body: SetUserRolesReq) {
|
||||
async setRoles(body: SetUserRolesReq, customerId: string) {
|
||||
const { roleNames, userId } = body;
|
||||
const clearRoles = roleNames && roleNames.length === 0;
|
||||
const { user } = await lastValueFrom(
|
||||
@@ -115,6 +118,7 @@ export class UsersService implements OnModuleInit {
|
||||
roleIds: [],
|
||||
roleNames,
|
||||
clearRoles,
|
||||
customerId,
|
||||
}),
|
||||
);
|
||||
if (user) {
|
||||
|
||||
Reference in New Issue
Block a user