Merge branch 'develop' of github.com:Frappet/bma-ehr-organization into develop

This commit is contained in:
kittapath 2024-11-14 15:00:23 +07:00
commit 81a9a019c3

View file

@ -53,7 +53,7 @@ import { PosMasterAct } from "../entities/PosMasterAct";
import { sendToQueue } from "../services/rabbitmq"; import { sendToQueue } from "../services/rabbitmq";
import { PosLevel } from "../entities/PosLevel"; import { PosLevel } from "../entities/PosLevel";
import { PosType } from "../entities/PosType"; import { PosType } from "../entities/PosType";
import { addUserRoles, createUser, getRoles, deleteUser } from "../keycloak"; import { addUserRoles, createUser, getRoles, deleteUser, enableStatus } from "../keycloak";
import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation"; import { ProfileEducation, CreateProfileEducation } from "../entities/ProfileEducation";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate"; import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate";
@ -2098,28 +2098,35 @@ export class CommandController extends Controller {
} }
const returnWork = await checkReturnCommandType(String(item.commandId)); const returnWork = await checkReturnCommandType(String(item.commandId));
if (returnWork && item.isGovernment) { if (returnWork && item.isGovernment) {
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, { if (profile.keycloak != null ) {
firstName: profile.firstName, const enableActive = await enableStatus(profile.keycloak, true);
lastName: profile.lastName, if (!enableActive) throw new Error("Failed. Cannot change enable status.");
});
if (typeof userKeycloakId !== "string") {
throw new Error(userKeycloakId.errorMessage);
} }
const list = await getRoles(); else {
if (!Array.isArray(list)) const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
throw new Error("Failed. Cannot get role(s) data from the server."); firstName: profile.firstName,
const result = await addUserRoles( lastName: profile.lastName,
userKeycloakId, });
list if (typeof userKeycloakId !== "string") {
.filter((v) => v.name === "USER") throw new Error(userKeycloakId.errorMessage);
.map((x) => ({ }
id: x.id, const list = await getRoles();
name: x.name, if (!Array.isArray(list))
})), throw new Error("Failed. Cannot get role(s) data from the server.");
); const result = await addUserRoles(
if (!result) throw new Error("Failed. Cannot set user's role."); userKeycloakId,
profile.keycloak = userKeycloakId; list
profile.roleKeycloaks = roleKeycloak ? [roleKeycloak] : [] .filter((v) => v.name === "USER")
.map((x) => ({
id: x.id,
name: x.name,
})),
);
if (!result) throw new Error("Failed. Cannot set user's role.");
profile.keycloak = userKeycloakId;
}
profile.isActive = true;
profile.roleKeycloaks = profile.roleKeycloaks ?? [roleKeycloak];
} }
await this.profileRepository.save(profile); await this.profileRepository.save(profile);
}), }),
@ -2522,12 +2529,17 @@ export class CommandController extends Controller {
if (item.isLeave == true && !exceptClear) { if (item.isLeave == true && !exceptClear) {
await removeProfileInOrganize(_profile.id, "OFFICER"); await removeProfileInOrganize(_profile.id, "OFFICER");
} }
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
const enableActive = await enableStatus(_profile.keycloak, false);
if (!enableActive) throw new Error("Failed. Cannot change enable status.");
_profile.isActive = false;
}
const clearProfile = await checkCommandType(String(item.commandId)); const clearProfile = await checkCommandType(String(item.commandId));
if (clearProfile) { if (clearProfile) {
if (_profile.keycloak != null) { if (_profile.keycloak != null) {
const delUserKeycloak = await deleteUser(_profile.keycloak); const delUserKeycloak = await deleteUser(_profile.keycloak);
if (delUserKeycloak) _profile.keycloak = _null; if (delUserKeycloak) _profile.keycloak = _null;
profile.roleKeycloaks = []; _profile.roleKeycloaks = [];
} }
_profile.position = _null; _profile.position = _null;
_profile.posTypeId = _null; _profile.posTypeId = _null;