fix
This commit is contained in:
parent
6e5f20ed18
commit
055173a038
4 changed files with 57 additions and 3 deletions
|
|
@ -24,6 +24,8 @@ import {
|
|||
ProfileChangeName,
|
||||
UpdateProfileChangeName,
|
||||
} from "../entities/ProfileChangeName";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { updateName } from "../keycloak";
|
||||
|
||||
@Route("api/v1/org/profile/changeName")
|
||||
@Tags("ProfileChangeName")
|
||||
|
|
@ -145,6 +147,16 @@ export class ProfileChangeNameController extends Controller {
|
|||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileRepository.save(profile);
|
||||
|
||||
// if (profile != null) {
|
||||
// const result = await updateName(profile.id, profile.firstName, profile.lastName,req);
|
||||
|
||||
// const _mapData = {
|
||||
// data: mappedData,
|
||||
// total: total,
|
||||
// };
|
||||
|
||||
// }
|
||||
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3150,6 +3150,7 @@ export class ProfileController extends Controller {
|
|||
case "citizenId":
|
||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||
where: {
|
||||
keycloak: IsNull(),
|
||||
citizenId: Like(`%${body.keyword}%`),
|
||||
},
|
||||
relations: ["posType", "posLevel", "current_holders", "profileSalary"],
|
||||
|
|
@ -3289,6 +3290,6 @@ export class ProfileController extends Controller {
|
|||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess({data: mapDataProfile , total});
|
||||
return new HttpSuccess({ data: mapDataProfile, total });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2931,7 +2931,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
const skip = (page - 1) * pageSize;
|
||||
const take = pageSize;
|
||||
switch (body.fieldName) {
|
||||
case "idcard":
|
||||
case "citizenId":
|
||||
[findProfile, total] = await this.profileRepo.findAndCount({
|
||||
where: {
|
||||
keycloak: IsNull(),
|
||||
|
|
@ -3049,7 +3049,7 @@ export class ProfileEmployeeController extends Controller {
|
|||
firstName: item.firstName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
idcard: item.citizenId,
|
||||
citizenId: item.citizenId,
|
||||
email: item.email,
|
||||
phone: item.phone,
|
||||
name: fullName,
|
||||
|
|
|
|||
|
|
@ -203,6 +203,45 @@ export async function editUser(userId: string, opts: Record<string, any>) {
|
|||
const id = path?.split("/").at(-1);
|
||||
return id || true;
|
||||
}
|
||||
/**
|
||||
* Update keycloak user by uuid
|
||||
*
|
||||
* Client must have permission to manage realm's user
|
||||
*
|
||||
* @returns user uuid or true if success, false otherwise.
|
||||
*/
|
||||
export async function updateName(
|
||||
userId: string,
|
||||
firstName: string,
|
||||
lastName: string,
|
||||
opts: Record<string, any>,
|
||||
) {
|
||||
const { password, ...rest } = opts;
|
||||
|
||||
const res = await fetch(`${KC_URL}/admin/realms/${KC_REALM}/users/${userId}`, {
|
||||
// prettier-ignore
|
||||
headers: {
|
||||
"authorization": `Bearer ${await getToken()}`,
|
||||
"content-type": `application/json`,
|
||||
},
|
||||
method: "PUT",
|
||||
body: JSON.stringify({
|
||||
enabled: true,
|
||||
credentials: (password && [{ type: "password", value: opts?.password }]) || undefined,
|
||||
...rest,
|
||||
}),
|
||||
}).catch((e) => console.log("Keycloak Error: ", e));
|
||||
|
||||
if (!res) return false;
|
||||
if (!res.ok) {
|
||||
// return Boolean(console.error("Keycloak Error Response: ", await res.json()));
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
const path = res.headers.get("Location");
|
||||
const id = path?.split("/").at(-1);
|
||||
return id || true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete keycloak user by uuid
|
||||
|
|
@ -588,4 +627,6 @@ export async function removeUserGroup(userId: string, groupId: string) {
|
|||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue