This commit is contained in:
AnandaTon 2024-05-31 10:48:03 +07:00
commit 9f7203b798

View file

@ -28,7 +28,7 @@ import {
removeUserGroup, removeUserGroup,
removeUserRoles, removeUserRoles,
getRoleMappings, getRoleMappings,
getUserCount getUserCount,
} from "../keycloak"; } from "../keycloak";
// import * as io from "../lib/websocket"; // import * as io from "../lib/websocket";
// import elasticsearch from "../elasticsearch"; // import elasticsearch from "../elasticsearch";
@ -159,7 +159,7 @@ export class KeycloakController extends Controller {
// role: body.roles || [], // role: body.roles || [],
// }; // };
// const addRole = await this.addRole(userId, _rolesUpdate); // const addRole = await this.addRole(userId, _rolesUpdate);
return chkUpdate return chkUpdate;
} }
@Delete("user/{userId}") @Delete("user/{userId}")
@ -208,26 +208,28 @@ export class KeycloakController extends Controller {
} }
@Get("user") @Get("user")
async getUserList(@Query() first = "", @Query() max = "" ,@Query() search = "") { async getUserList(@Query() first = "", @Query() max = "", @Query() search = "") {
const total = await getUserCount(); const total = await getUserCount();
const result = await getUserList(first, max, search); const result = await getUserList(first, max, search);
if (Array.isArray(result)) { if (Array.isArray(result)) {
const mappedData = await Promise.all(result.map(async (x) => { const mappedData = await Promise.all(
const roles = await getRoleMappings(x.id); result.map(async (x) => {
return { const roles = await getRoleMappings(x.id);
id: x.id, return {
username: x.username, id: x.id,
firstname: x.firstName, username: x.username,
lastname: x.lastName, firstname: x.firstName,
email: x.email, lastname: x.lastName,
roles: roles email: x.email,
}; roles: roles,
})); };
}),
);
const _mapData = { const _mapData = {
data: mappedData, data: mappedData,
total: total total: total,
}; };
return _mapData; return _mapData;
@ -272,4 +274,13 @@ export class KeycloakController extends Controller {
const result = await removeUserGroup(userId, groupId); const result = await removeUserGroup(userId, groupId);
if (!result) throw new Error("Failed. Cannot remove group to user."); 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;
}
} }