Merge branch 'develop' into adiDev

This commit is contained in:
AdisakKanthawilang 2024-10-29 09:44:08 +07:00
commit cca4e837bc
4 changed files with 92 additions and 4 deletions

View file

@ -39,6 +39,8 @@ import {
commandTypePath, commandTypePath,
removeProfileInOrganize, removeProfileInOrganize,
setLogDataDiff, setLogDataDiff,
checkReturnCommandType,
checkExceptCommandType,
checkCommandType, checkCommandType,
} from "../interfaces/utils"; } from "../interfaces/utils";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
@ -1837,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);
}), }),
); );
@ -2113,7 +2139,7 @@ export class CommandController extends Controller {
// ประวัติตำแหน่ง // ประวัติตำแหน่ง
const data = new ProfileSalary(); const data = new ProfileSalary();
const meta = { const meta = {
profileId: item.profileId, profileId: profile.id,
date: item.date, date: item.date,
refCommandNo: item.refCommandNo, refCommandNo: item.refCommandNo,
templateDoc: item.salaryRef, templateDoc: item.salaryRef,
@ -2185,7 +2211,8 @@ export class CommandController extends Controller {
profile.lastUpdateUserId = req.user.sub; profile.lastUpdateUserId = req.user.sub;
profile.lastUpdateFullName = req.user.name; profile.lastUpdateFullName = req.user.name;
profile.lastUpdatedAt = new Date(); profile.lastUpdatedAt = new Date();
if (item.isLeave == true) { const exceptClear = await checkExceptCommandType(String(item.commandId));
if (item.isLeave == true && !exceptClear) {
await removeProfileInOrganize(profile.id, "OFFICER"); await removeProfileInOrganize(profile.id, "OFFICER");
} }
const clearProfile = await checkCommandType(String(item.commandId)); const clearProfile = await checkCommandType(String(item.commandId));

View file

@ -3885,7 +3885,7 @@ export class ProfileController extends Controller {
}, },
relations: ["orgChild1"], relations: ["orgChild1"],
}); });
if (posMasters == null || posMasters.orgChild1 == null) { if (posMasters == null) {
return new HttpSuccess({ return new HttpSuccess({
isOfficer: null, isOfficer: null,
rootId: null, rootId: null,
@ -3896,7 +3896,7 @@ export class ProfileController extends Controller {
}); });
} }
return new HttpSuccess({ return new HttpSuccess({
isOfficer: posMasters?.orgChild1?.isOfficer || null, isOfficer: posMasters?.orgChild1?.isOfficer || false,
rootId: posMasters?.orgRootId || null, rootId: posMasters?.orgRootId || null,
child1Id: posMasters?.orgChild1Id || null, child1Id: posMasters?.orgChild1Id || null,
child2Id: posMasters?.orgChild2Id || null, child2Id: posMasters?.orgChild2Id || null,

View file

@ -156,6 +156,39 @@ export class WorkflowController extends Controller {
}), }),
); );
const _workflow = await this.workflowRepo.findOne({
where: { id: workflow.id },
relations: ["stateOperatorUsers"],
});
if (!_workflow) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่สามารถดำเนินการกระบวนการนี้ได้");
const _state = await this.stateRepo.findOne({
where: {
id: _workflow.stateId,
},
relations: ["stateOperators"],
});
if (!_state) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลขั้นตอนการอนุมัติ");
let profileNow = _workflow.stateOperatorUsers
.filter((x) => _state.stateOperators.map((s) => s.operator).includes(x.operator))
.map((x) => ({
receiverUserId: x.profile,
notiLink: "",
}));
await new CallAPI()
.PostData(req, "/placement/noti/profiles", {
subject: `รายการถูกส่ง`,
body: `รายการถูกส่ง`,
receiverUserIds: profileNow,
payload: "", //แนบไฟล์
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.catch((error) => {
console.error("Error calling API:", error);
});
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -175,6 +175,34 @@ 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) {
const commandRepository = AppDataSource.getRepository(Command);
const _type = await commandRepository.findOne({
where: {
id: commandId
},
relations: ["commandType"],
});
if (!["C-PM-25", "C-PM-26"].includes(String(_type?.commandType.code))) {
return false;
}
return true;
}
export async function checkCommandType(commandId: string) { export async function checkCommandType(commandId: string) {
const commandRepository = AppDataSource.getRepository(Command); const commandRepository = AppDataSource.getRepository(Command);
const _type = await commandRepository.findOne({ const _type = await commandRepository.findOne({