no message

This commit is contained in:
kittapath 2025-01-29 12:13:16 +07:00
parent 0b8f9b6c23
commit a48656bdc9
2 changed files with 22 additions and 26 deletions

View file

@ -30,7 +30,7 @@ import {
getRoleMappings,
getUserCount,
enableStatus,
getUserByUsername
getUserByUsername,
} from "../keycloak";
import { AppDataSource } from "../database/data-source";
import { Profile } from "../entities/Profile";
@ -97,15 +97,21 @@ export class KeycloakController extends Controller {
profileId?: string;
},
) {
const userId = await createUser(body.username, body.password, {
firstName: body.firstName,
lastName: body.lastName,
// email: body.email,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
const checkUser = await getUserByUsername(body.username);
let userId: any = "";
if (checkUser.length == 0) {
userId = await createUser(body.username, body.password, {
firstName: body.firstName,
lastName: body.lastName,
// email: body.email,
});
if (typeof userId !== "string") {
throw new Error(userId.errorMessage);
}
} else {
userId = checkUser[0].id;
}
const list = await getRoles();
if (!Array.isArray(list)) throw new Error("Failed. Cannot get role(s) data from the server.");
const result = await addUserRoles(
@ -709,7 +715,7 @@ export class KeycloakController extends Controller {
roles: rolesData,
};
return userDataWithRoles
return userDataWithRoles;
}
@Put("user/{userId}/enableStatus/{status}") //#log?

View file

@ -227,14 +227,7 @@ export async function getUserListOrg(first = "", max = "", search = "", userIds:
}
export async function getUserCountOrg(first = "", max = "", search = "", userIds: string[] = []) {
console.log(userIds);
const userIdsParam = userIds.join(",");
console.log(userIdsParam);
console.log("xxxxxxxxxxxxxxxxx");
console.log(
`${KC_URL}/admin/realms/${KC_REALMS}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}${userIdsParam && userIdsParam != "" ? `&id=${userIdsParam}` : ""}`,
);
console.log("aaaaaaaaaaaaaaaaaa");
const res = await fetch(
`${KC_URL}/admin/realms/${KC_REALMS}/users/count?first=${first || "0"}&max=${max || "-1"}${search ? `&search=${search}` : ""}${userIdsParam && userIdsParam != "" ? `&id=${userIdsParam}` : ""}`,
{
@ -497,18 +490,15 @@ export async function getUserRoles(userId: string) {
* @returns true if success, false otherwise.
*/
export async function addUserRoles(userId: string, roles: { id: string; name: string }[]) {
const res = await fetch(
`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}`,
{
// prettier-ignore
headers: {
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALMS}/users/${userId}`, {
// prettier-ignore
headers: {
"authorization": `Bearer ${await getToken()}`,
"content-type": `application/json`,
},
method: "POST",
body: JSON.stringify(roles),
},
).catch((e) => console.log(e));
method: "POST",
body: JSON.stringify(roles),
}).catch((e) => console.log(e));
if (!res) return false;
if (!res.ok) {