getRoleUSer
This commit is contained in:
parent
77c7574809
commit
438c153651
1 changed files with 28 additions and 17 deletions
|
|
@ -28,7 +28,7 @@ import {
|
|||
removeUserGroup,
|
||||
removeUserRoles,
|
||||
getRoleMappings,
|
||||
getUserCount
|
||||
getUserCount,
|
||||
} from "../keycloak";
|
||||
// import * as io from "../lib/websocket";
|
||||
// import elasticsearch from "../elasticsearch";
|
||||
|
|
@ -159,7 +159,7 @@ export class KeycloakController extends Controller {
|
|||
// role: body.roles || [],
|
||||
// };
|
||||
// const addRole = await this.addRole(userId, _rolesUpdate);
|
||||
return chkUpdate
|
||||
return chkUpdate;
|
||||
}
|
||||
|
||||
@Delete("user/{userId}")
|
||||
|
|
@ -208,28 +208,30 @@ export class KeycloakController extends Controller {
|
|||
}
|
||||
|
||||
@Get("user")
|
||||
async getUserList(@Query() first = "", @Query() max = "" ,@Query() search = "") {
|
||||
async getUserList(@Query() first = "", @Query() max = "", @Query() search = "") {
|
||||
const total = await getUserCount();
|
||||
const result = await getUserList(first, max, search);
|
||||
|
||||
if (Array.isArray(result)) {
|
||||
const mappedData = await Promise.all(result.map(async (x) => {
|
||||
const roles = await getRoleMappings(x.id);
|
||||
return {
|
||||
id: x.id,
|
||||
username: x.username,
|
||||
firstname: x.firstName,
|
||||
lastname: x.lastName,
|
||||
email: x.email,
|
||||
roles: roles
|
||||
};
|
||||
}));
|
||||
|
||||
const mappedData = await Promise.all(
|
||||
result.map(async (x) => {
|
||||
const roles = await getRoleMappings(x.id);
|
||||
return {
|
||||
id: x.id,
|
||||
username: x.username,
|
||||
firstname: x.firstName,
|
||||
lastname: x.lastName,
|
||||
email: x.email,
|
||||
roles: roles,
|
||||
};
|
||||
}),
|
||||
);
|
||||
|
||||
const _mapData = {
|
||||
data: mappedData,
|
||||
total: total
|
||||
total: total,
|
||||
};
|
||||
|
||||
|
||||
return _mapData;
|
||||
}
|
||||
throw new Error("Failed. Cannot get user list.");
|
||||
|
|
@ -272,4 +274,13 @@ export class KeycloakController extends Controller {
|
|||
const result = await removeUserGroup(userId, groupId);
|
||||
if (!result) throw new Error("Failed. Cannot remove group to user.");
|
||||
}
|
||||
|
||||
@Get("user/role/{id}")
|
||||
async getRoleUser(@Path("id") id: string) {
|
||||
const result = await getRoleMappings(id);
|
||||
if (!result) {
|
||||
throw new Error("Role mappings not found");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue