create user keycloak เมื่อกลับเข้ารับราชการ
This commit is contained in:
parent
1b3f42fd85
commit
08706f57ed
2 changed files with 39 additions and 0 deletions
|
|
@ -39,6 +39,7 @@ import {
|
||||||
commandTypePath,
|
commandTypePath,
|
||||||
removeProfileInOrganize,
|
removeProfileInOrganize,
|
||||||
setLogDataDiff,
|
setLogDataDiff,
|
||||||
|
checkReturnCommandType,
|
||||||
checkExceptCommandType,
|
checkExceptCommandType,
|
||||||
checkCommandType,
|
checkCommandType,
|
||||||
} from "../interfaces/utils";
|
} from "../interfaces/utils";
|
||||||
|
|
@ -1838,6 +1839,30 @@ export class CommandController extends Controller {
|
||||||
profile.posTypeId = _null;
|
profile.posTypeId = _null;
|
||||||
profile.posLevelId = _null;
|
profile.posLevelId = _null;
|
||||||
}
|
}
|
||||||
|
const returnWork = await checkReturnCommandType(String(item.commandId));
|
||||||
|
if(returnWork && item.isGovernment) {
|
||||||
|
const userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
|
||||||
|
firstName: profile.firstName,
|
||||||
|
lastName: profile.lastName,
|
||||||
|
});
|
||||||
|
if (typeof userKeycloakId !== "string") {
|
||||||
|
throw new Error(userKeycloakId.errorMessage);
|
||||||
|
}
|
||||||
|
const list = await getRoles();
|
||||||
|
if (!Array.isArray(list))
|
||||||
|
throw new Error("Failed. Cannot get role(s) data from the server.");
|
||||||
|
const result = await addUserRoles(
|
||||||
|
userKeycloakId,
|
||||||
|
list
|
||||||
|
.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;
|
||||||
|
}
|
||||||
await this.profileRepository.save(profile);
|
await this.profileRepository.save(profile);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -175,6 +175,20 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function checkReturnCommandType(commandId: string) {
|
||||||
|
const commandRepository = AppDataSource.getRepository(Command);
|
||||||
|
const _type = await commandRepository.findOne({
|
||||||
|
where: {
|
||||||
|
id: commandId
|
||||||
|
},
|
||||||
|
relations: ["commandType"],
|
||||||
|
});
|
||||||
|
if (!["C-PM-08", "C-PM-09"].includes(String(_type?.commandType.code))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
export async function checkExceptCommandType(commandId: string) {
|
export async function checkExceptCommandType(commandId: string) {
|
||||||
const commandRepository = AppDataSource.getRepository(Command);
|
const commandRepository = AppDataSource.getRepository(Command);
|
||||||
const _type = await commandRepository.findOne({
|
const _type = await commandRepository.findOne({
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue