fix: #2239
All checks were successful
Build & Deploy on Dev / build (push) Successful in 48s

This commit is contained in:
Adisak 2026-02-06 14:55:59 +07:00
parent 1696890f74
commit 8a649086f7
3 changed files with 242 additions and 164 deletions

View file

@ -305,6 +305,22 @@ class CheckAuth {
public async PermissionOrgUserUpdate(req: RequestWithUser, system: string, profileId: string) {
return await this.PermissionOrgByUser(req, system, "UPDATE", profileId);
}
public async checkDna(request: RequestWithUser, keycloakId: any) {
try {
const result = await new CallAPI().GetData(
request,
`/org/finddna-by-keycloak/${keycloakId}`,
false
);
return result;
} catch (error) {
console.error("Error calling API:", error);
throw error;
}
}
}
export default CheckAuth;

View file

@ -72,7 +72,7 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
});
// console.log("endDateFristRec", endDateFristRec.dateGovernment);
const calculateDuration = (startDate: any, endDate: any , inclusive = false) => {
const calculateDuration = (startDate: any, endDate: any, inclusive = false) => {
if (inclusive) {
endDate = new Date(endDate.getTime() + 86400000); // +1 วัน
}
@ -107,9 +107,9 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
});
}
// const firstStartDate = new Date(records[0].date);
const firstStartDate = !bkk
? profile?.dateAppoint ? profile?.dateAppoint : new Date()
: profile?.dateStart ? profile?.dateStart : new Date() ;
const firstStartDate = !bkk
? profile?.dateAppoint ? profile?.dateAppoint : new Date()
: profile?.dateStart ? profile?.dateStart : new Date();
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
// console.log("firstStartDate1", firstStartDate);
@ -143,37 +143,37 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
for (let i = 0; i < records_middle.length; i++) {
const current = records_middle[i];
const next = records_middle[i + 1];
// นับเฉพาะช่วงที่เป็นราชการ
if (current.isGovernment === true) {
const startDate = new Date(current.dateGovernment);
const endDate = next ? new Date(next.dateGovernment) : new Date();
const { years, months, days } = calculateDuration(startDate, endDate);
totalYears2 += years;
totalMonths2 += months;
totalDays2 += days;
// console.log(`✔ นับช่วง ${startDate.toISOString()} → ${endDate.toISOString()} ได้ ${years} ปี ${months} เดือน ${days} วัน`);
}
}
// else {
// console.log(`❌ ไม่รวมช่วง ${current.dateGovernment} เพราะ isGovernment = false`);
// }
}
//ตั้งแต่วันที่กลับมารับราขการไปจนถึงรวมถึงวันที่ปัจจุบัน
const adjustTotal = (years:number, months:number, days:number) => {
const adjustTotal = (years: number, months: number, days: number) => {
const daysInThisMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate();
if (days >= daysInThisMonth) {
months += Math.floor(days / daysInThisMonth);
days %= daysInThisMonth;
}
if (months >= 12) {
years += Math.floor(months / 12);
months %= 12;
}
return { years, months, days };
};
@ -192,10 +192,10 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
const finalAdjusted = adjustTotal(sumYears, sumMonths, sumDays);
return {
year: finalAdjusted.years,
month: finalAdjusted.months,
day: finalAdjusted.days,
};
year: finalAdjusted.years,
month: finalAdjusted.months,
day: finalAdjusted.days,
};
}
export function calculateRetireDate(birthDate: Date) {
@ -262,11 +262,11 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
.getOne();
const draftRevision = await AppDataSource.getRepository(OrgRevision)
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = true")
.andWhere("orgRevision.orgRevisionIsCurrent = false")
.getOne();
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = true")
.andWhere("orgRevision.orgRevisionIsCurrent = false")
.getOne();
if (!currentRevision && !draftRevision) {
return;
}
@ -354,31 +354,31 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
}
export async function removePostMasterAct(profileId: string) {
const currentRevision = await AppDataSource.getRepository(OrgRevision)
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
const currentRevision = await AppDataSource.getRepository(OrgRevision)
.createQueryBuilder("orgRevision")
.where("orgRevision.orgRevisionIsDraft = false")
.andWhere("orgRevision.orgRevisionIsCurrent = true")
.getOne();
if (!currentRevision) {
return;
}
if (!currentRevision) {
return;
}
const findProfileInposMaster = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: currentRevision?.id })
.andWhere("posMaster.current_holderId = :profileId", { profileId })
.getOne();
const findProfileInposMaster = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: currentRevision?.id })
.andWhere("posMaster.current_holderId = :profileId", { profileId })
.getOne();
if (!findProfileInposMaster) {
return;
}
if (!findProfileInposMaster) {
return;
}
const posMasterAct = await AppDataSource.getRepository(PosMasterAct)
.createQueryBuilder("posMasterAct")
.where("posMasterAct.posMasterChildId = :posMasterChildId", { posMasterChildId: findProfileInposMaster.id })
.getMany();
await AppDataSource.getRepository(PosMasterAct).remove(posMasterAct);
const posMasterAct = await AppDataSource.getRepository(PosMasterAct)
.createQueryBuilder("posMasterAct")
.where("posMasterAct.posMasterChildId = :posMasterChildId", { posMasterChildId: findProfileInposMaster.id })
.getMany();
await AppDataSource.getRepository(PosMasterAct).remove(posMasterAct);
}
export async function checkReturnCommandType(commandId: string) {
@ -567,22 +567,22 @@ export function editLogSequence(req: RequestWithUser, index: number, data: LogSe
export async function checkQueueInProgress(queueName: string) {
const axios = require('axios');
// console.log("Checking queue in progress");
const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
auth: { username: process.env.RABBIT_USER , password: process.env.RABBIT_PASS },
});
// console.log("Checking queue in progress");
const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
auth: { username: process.env.RABBIT_USER, password: process.env.RABBIT_PASS },
});
const q = res.data;
const q = res.data;
// console.log(`Queue "${queueName}" has:`);
// console.log(` - ${q.messages_ready} messages ready`);
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
// console.log(`Queue "${queueName}" has:`);
// console.log(` - ${q.messages_ready} messages ready`);
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
if (q.messages_unacknowledged > 0) {
return true;
}
if (q.messages_unacknowledged > 0) {
return true;
}
return false;
return false;
}
export function chunkArray(array: any, size: number) {
@ -594,7 +594,7 @@ export function chunkArray(array: any, size: number) {
}
export async function PayloadSendNoti(commandId: string) {
if (!commandId)
if (!commandId)
return "";
const commandRepository = AppDataSource.getRepository(Command);
const _command = await commandRepository.findOne({
@ -606,8 +606,8 @@ export async function PayloadSendNoti(commandId: string) {
if (!_command || !_command.commandType)
return "";
const _payload = {
name: _command && _command.commandType
? `คำสั่ง${_command.commandType.name}`
name: _command && _command.commandType
? `คำสั่ง${_command.commandType.name}`
: "",
url: `${process.env.API_URL}/salary/file/ระบบออกคำสั่ง/คำสั่ง/${commandId}/คำสั่ง`,
isReport: true,
@ -616,8 +616,8 @@ export async function PayloadSendNoti(commandId: string) {
let attachments = {}
if (_command.commandType.isUploadAttachment === true) {
const _payloadAtt = {
name: _command && _command.commandType
? `เอกสารแนบท้ายคำสั่ง${_command.commandType.name}`
name: _command && _command.commandType
? `เอกสารแนบท้ายคำสั่ง${_command.commandType.name}`
: "",
url: `${process.env.API_URL}/salary/file/ระบบออกคำสั่ง/แนบท้าย/${commandId}/แนบท้าย`,
isReport: true,
@ -733,3 +733,23 @@ export function commandTypePath(commandCode: string): string | null {
return null;
}
}
export function resolveNodeLevel(data: any) {
if (data.child4DnaId) return 4;
if (data.child3DnaId) return 3;
if (data.child2DnaId) return 2;
if (data.child1DnaId) return 1;
if (data.rootDnaId) return 0;
return null;
}
export function resolveNodeId(data: any) {
return (
data.child4DnaId ??
data.child3DnaId ??
data.child2DnaId ??
data.child1DnaId ??
data.rootDnaId ??
null
);
}