merge
This commit is contained in:
commit
3177ffc42f
5 changed files with 265 additions and 188 deletions
|
|
@ -33,7 +33,12 @@ import { PosMaster } from "../entities/PosMaster";
|
||||||
import { Profile } from "../entities/Profile";
|
import { Profile } from "../entities/Profile";
|
||||||
import { RequestWithUser } from "../middlewares/user";
|
import { RequestWithUser } from "../middlewares/user";
|
||||||
import permission from "../interfaces/permission";
|
import permission from "../interfaces/permission";
|
||||||
import { checkQueueInProgress, setLogDataDiff } from "../interfaces/utils";
|
import {
|
||||||
|
checkQueueInProgress,
|
||||||
|
resolveNodeId,
|
||||||
|
resolveNodeLevel,
|
||||||
|
setLogDataDiff,
|
||||||
|
} from "../interfaces/utils";
|
||||||
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
|
import { sendToQueueOrg, sendToQueueOrgDraft } from "../services/rabbitmq";
|
||||||
import { PosType } from "../entities/PosType";
|
import { PosType } from "../entities/PosType";
|
||||||
import { PosLevel } from "../entities/PosLevel";
|
import { PosLevel } from "../entities/PosLevel";
|
||||||
|
|
@ -5513,6 +5518,9 @@ export class OrganizationController extends Controller {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const orgDna = await new permission().checkDna(request, request.user.sub);
|
||||||
|
let level: any = resolveNodeLevel(orgDna);
|
||||||
|
|
||||||
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
const orgRootData = await AppDataSource.getRepository(OrgRoot)
|
||||||
.createQueryBuilder("orgRoot")
|
.createQueryBuilder("orgRoot")
|
||||||
.where("orgRoot.orgRevisionId = :id", { id })
|
.where("orgRoot.orgRevisionId = :id", { id })
|
||||||
|
|
@ -5619,6 +5627,35 @@ export class OrganizationController extends Controller {
|
||||||
.getMany()
|
.getMany()
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
const cannotViewRootPosMaster =
|
||||||
|
_privilege.privilege === "PARENT" ||
|
||||||
|
(_privilege.privilege === "BROTHER" && level > 1) ||
|
||||||
|
(_privilege.privilege === "CHILD" && level > 0) ||
|
||||||
|
(_privilege.privilege === "NORMAL" && level != 0);
|
||||||
|
|
||||||
|
const cannotViewChild1PosMaster =
|
||||||
|
(_privilege.privilege === "PARENT" && level > 1) ||
|
||||||
|
(_privilege.privilege === "BROTHER" && level > 2) ||
|
||||||
|
(_privilege.privilege === "CHILD" && level > 1) ||
|
||||||
|
(_privilege.privilege === "NORMAL" && level !== 1);
|
||||||
|
|
||||||
|
const cannotViewChild2PosMaster =
|
||||||
|
(_privilege.privilege === "PARENT" && level > 2) ||
|
||||||
|
(_privilege.privilege === "BROTHER" && level > 3) ||
|
||||||
|
(_privilege.privilege === "CHILD" && level > 2) ||
|
||||||
|
(_privilege.privilege === "NORMAL" && level !== 2);
|
||||||
|
|
||||||
|
const cannotViewChild3PosMaster =
|
||||||
|
(_privilege.privilege === "PARENT" && level > 3) ||
|
||||||
|
(_privilege.privilege === "BROTHER" && level > 4) ||
|
||||||
|
(_privilege.privilege === "CHILD" && level > 3) ||
|
||||||
|
(_privilege.privilege === "NORMAL" && level !== 3);
|
||||||
|
|
||||||
|
const cannotViewChild4PosMaster =
|
||||||
|
(_privilege.privilege === "PARENT" && level > 4) ||
|
||||||
|
(_privilege.privilege === "CHILD" && level > 4) ||
|
||||||
|
(_privilege.privilege === "NORMAL" && level !== 4);
|
||||||
|
|
||||||
// const formattedData = orgRootData.map((orgRoot) => {
|
// const formattedData = orgRootData.map((orgRoot) => {
|
||||||
const formattedData = await Promise.all(
|
const formattedData = await Promise.all(
|
||||||
orgRootData.map(async (orgRoot) => {
|
orgRootData.map(async (orgRoot) => {
|
||||||
|
|
@ -5633,27 +5670,29 @@ export class OrganizationController extends Controller {
|
||||||
orgRootName: orgRoot.orgRootName,
|
orgRootName: orgRoot.orgRootName,
|
||||||
labelName:
|
labelName:
|
||||||
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
orgRoot.orgRootName + " " + orgRoot.orgRootCode + "00" + " " + orgRoot.orgRootShortName,
|
||||||
posMaster: await Promise.all(
|
posMaster: cannotViewRootPosMaster
|
||||||
orgRoot.posMasters
|
? []
|
||||||
.filter(
|
: await Promise.all(
|
||||||
(x) =>
|
orgRoot.posMasters
|
||||||
x.orgChild1Id == null &&
|
.filter(
|
||||||
// x.current_holderId != null &&
|
(x) =>
|
||||||
x.isDirector === true,
|
x.orgChild1Id == null &&
|
||||||
)
|
// x.current_holderId != null &&
|
||||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
x.isDirector === true,
|
||||||
// .slice(0, 3) // Select the first 3 rows
|
)
|
||||||
.map(async (x) => ({
|
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||||
posmasterId: x.id,
|
// .slice(0, 3) // Select the first 3 rows
|
||||||
posNo: `${orgRoot.orgRootShortName} ${x.posMasterNo}`,
|
.map(async (x) => ({
|
||||||
orgTreeId: orgRoot.id,
|
posmasterId: x.id,
|
||||||
orgLevel: 0,
|
posNo: `${orgRoot.orgRootShortName} ${x.posMasterNo}`,
|
||||||
fullNameCurrentHolder:
|
orgTreeId: orgRoot.id,
|
||||||
x.current_holder == null
|
orgLevel: 0,
|
||||||
? null
|
fullNameCurrentHolder:
|
||||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
x.current_holder == null
|
||||||
})),
|
? null
|
||||||
),
|
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||||
|
})),
|
||||||
|
),
|
||||||
children: await Promise.all(
|
children: await Promise.all(
|
||||||
orgChild1Data
|
orgChild1Data
|
||||||
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
|
.filter((orgChild1) => orgChild1.orgRootId === orgRoot.id)
|
||||||
|
|
@ -5681,27 +5720,29 @@ export class OrganizationController extends Controller {
|
||||||
"00" +
|
"00" +
|
||||||
" " +
|
" " +
|
||||||
orgRoot.orgRootShortName,
|
orgRoot.orgRootShortName,
|
||||||
posMaster: await Promise.all(
|
posMaster: cannotViewChild1PosMaster
|
||||||
orgChild1.posMasters
|
? []
|
||||||
.filter(
|
: await Promise.all(
|
||||||
(x) =>
|
orgChild1.posMasters
|
||||||
x.orgChild2Id == null &&
|
.filter(
|
||||||
// x.current_holderId != null &&
|
(x) =>
|
||||||
x.isDirector === true,
|
x.orgChild2Id == null &&
|
||||||
)
|
// x.current_holderId != null &&
|
||||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
x.isDirector === true,
|
||||||
// .slice(0, 3) // Select the first 3 rows
|
)
|
||||||
.map(async (x) => ({
|
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||||
posmasterId: x.id,
|
// .slice(0, 3) // Select the first 3 rows
|
||||||
posNo: `${orgChild1.orgChild1ShortName} ${x.posMasterNo}`,
|
.map(async (x) => ({
|
||||||
orgTreeId: orgChild1.id,
|
posmasterId: x.id,
|
||||||
orgLevel: 1,
|
posNo: `${orgChild1.orgChild1ShortName} ${x.posMasterNo}`,
|
||||||
fullNameCurrentHolder:
|
orgTreeId: orgChild1.id,
|
||||||
x.current_holder == null
|
orgLevel: 1,
|
||||||
? null
|
fullNameCurrentHolder:
|
||||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
x.current_holder == null
|
||||||
})),
|
? null
|
||||||
),
|
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
|
||||||
children: await Promise.all(
|
children: await Promise.all(
|
||||||
orgChild2Data
|
orgChild2Data
|
||||||
|
|
@ -5737,27 +5778,29 @@ export class OrganizationController extends Controller {
|
||||||
"00" +
|
"00" +
|
||||||
" " +
|
" " +
|
||||||
orgRoot.orgRootShortName,
|
orgRoot.orgRootShortName,
|
||||||
posMaster: await Promise.all(
|
posMaster: cannotViewChild2PosMaster
|
||||||
orgChild2.posMasters
|
? []
|
||||||
.filter(
|
: await Promise.all(
|
||||||
(x) =>
|
orgChild2.posMasters
|
||||||
x.orgChild3Id == null &&
|
.filter(
|
||||||
// x.current_holderId != null &&
|
(x) =>
|
||||||
x.isDirector === true,
|
x.orgChild3Id == null &&
|
||||||
)
|
// x.current_holderId != null &&
|
||||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
x.isDirector === true,
|
||||||
// .slice(0, 3) // Select the first 3 rows
|
)
|
||||||
.map(async (x) => ({
|
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||||
posmasterId: x.id,
|
// .slice(0, 3) // Select the first 3 rows
|
||||||
posNo: `${orgChild2.orgChild2ShortName} ${x.posMasterNo}`,
|
.map(async (x) => ({
|
||||||
orgTreeId: orgChild2.id,
|
posmasterId: x.id,
|
||||||
orgLevel: 2,
|
posNo: `${orgChild2.orgChild2ShortName} ${x.posMasterNo}`,
|
||||||
fullNameCurrentHolder:
|
orgTreeId: orgChild2.id,
|
||||||
x.current_holder == null
|
orgLevel: 2,
|
||||||
? null
|
fullNameCurrentHolder:
|
||||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
x.current_holder == null
|
||||||
})),
|
? null
|
||||||
),
|
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
|
||||||
children: await Promise.all(
|
children: await Promise.all(
|
||||||
orgChild3Data
|
orgChild3Data
|
||||||
|
|
@ -5800,27 +5843,29 @@ export class OrganizationController extends Controller {
|
||||||
"00" +
|
"00" +
|
||||||
" " +
|
" " +
|
||||||
orgRoot.orgRootShortName,
|
orgRoot.orgRootShortName,
|
||||||
posMaster: await Promise.all(
|
posMaster: cannotViewChild3PosMaster
|
||||||
orgChild3.posMasters
|
? []
|
||||||
.filter(
|
: await Promise.all(
|
||||||
(x) =>
|
orgChild3.posMasters
|
||||||
x.orgChild4Id == null &&
|
.filter(
|
||||||
// x.current_holderId != null &&
|
(x) =>
|
||||||
x.isDirector === true,
|
x.orgChild4Id == null &&
|
||||||
)
|
// x.current_holderId != null &&
|
||||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
x.isDirector === true,
|
||||||
// .slice(0, 3) // Select the first 3 rows
|
)
|
||||||
.map(async (x) => ({
|
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||||
posmasterId: x.id,
|
// .slice(0, 3) // Select the first 3 rows
|
||||||
posNo: `${orgChild3.orgChild3ShortName} ${x.posMasterNo}`,
|
.map(async (x) => ({
|
||||||
orgTreeId: orgChild3.id,
|
posmasterId: x.id,
|
||||||
orgLevel: 3,
|
posNo: `${orgChild3.orgChild3ShortName} ${x.posMasterNo}`,
|
||||||
fullNameCurrentHolder:
|
orgTreeId: orgChild3.id,
|
||||||
x.current_holder == null
|
orgLevel: 3,
|
||||||
? null
|
fullNameCurrentHolder:
|
||||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
x.current_holder == null
|
||||||
})),
|
? null
|
||||||
),
|
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
|
||||||
children: await Promise.all(
|
children: await Promise.all(
|
||||||
orgChild4Data
|
orgChild4Data
|
||||||
|
|
@ -5870,26 +5915,28 @@ export class OrganizationController extends Controller {
|
||||||
"00" +
|
"00" +
|
||||||
" " +
|
" " +
|
||||||
orgRoot.orgRootShortName,
|
orgRoot.orgRootShortName,
|
||||||
posMaster: await Promise.all(
|
posMaster: cannotViewChild4PosMaster
|
||||||
orgChild4.posMasters
|
? []
|
||||||
.filter(
|
: await Promise.all(
|
||||||
(x) =>
|
orgChild4.posMasters
|
||||||
// x.current_holderId != null &&
|
.filter(
|
||||||
x.isDirector === true,
|
(x) =>
|
||||||
)
|
// x.current_holderId != null &&
|
||||||
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
x.isDirector === true,
|
||||||
// .slice(0, 3) // Select the first 3 rows
|
)
|
||||||
.map(async (x) => ({
|
// .sort((a, b) => a.posMasterOrder - b.posMasterOrder) // Sort by posMasterOrder ASC
|
||||||
posmasterId: x.id,
|
// .slice(0, 3) // Select the first 3 rows
|
||||||
posNo: `${orgChild4.orgChild4ShortName} ${x.posMasterNo}`,
|
.map(async (x) => ({
|
||||||
orgTreeId: orgChild4.id,
|
posmasterId: x.id,
|
||||||
orgLevel: 4,
|
posNo: `${orgChild4.orgChild4ShortName} ${x.posMasterNo}`,
|
||||||
fullNameCurrentHolder:
|
orgTreeId: orgChild4.id,
|
||||||
x.current_holder == null
|
orgLevel: 4,
|
||||||
? null
|
fullNameCurrentHolder:
|
||||||
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
x.current_holder == null
|
||||||
})),
|
? null
|
||||||
),
|
: `${x.current_holder.prefix}${x.current_holder.firstName} ${x.current_holder.lastName}`,
|
||||||
|
})),
|
||||||
|
),
|
||||||
})),
|
})),
|
||||||
),
|
),
|
||||||
})),
|
})),
|
||||||
|
|
|
||||||
|
|
@ -1339,9 +1339,7 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
// add insert to profile salary backup
|
// add insert to profile salary backup
|
||||||
const profileSalaryBeforeDelete = await queryRunner.manager.find(ProfileSalary, {
|
const profileSalaryBeforeDelete = await queryRunner.manager.find(ProfileSalary, {
|
||||||
where: {
|
where: {
|
||||||
...(isOfficer
|
...(isOfficer ? { profileId: body.profileId } : { profileEmployeeId: body.profileId }),
|
||||||
? { profileId: body.profileId }
|
|
||||||
: { profileEmployeeId: body.profileId }),
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -1350,7 +1348,7 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
queryRunner.manager.create(ProfileSalaryBackup, {
|
queryRunner.manager.create(ProfileSalaryBackup, {
|
||||||
...salary,
|
...salary,
|
||||||
profileSalaryId: id,
|
profileSalaryId: id,
|
||||||
})
|
}),
|
||||||
);
|
);
|
||||||
await queryRunner.manager.insert(ProfileSalaryBackup, backupRows);
|
await queryRunner.manager.insert(ProfileSalaryBackup, backupRows);
|
||||||
}
|
}
|
||||||
|
|
@ -1389,17 +1387,11 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
lastUpdatedAt: dateNow,
|
lastUpdatedAt: dateNow,
|
||||||
};
|
};
|
||||||
|
|
||||||
const salaryRows = toInsert.filter(
|
const salaryRows = toInsert.filter((x) => !["17", "18"].includes(x.commandCode));
|
||||||
x => !["17", "18"].includes(x.commandCode)
|
// ส่งไปรักษาการ
|
||||||
);
|
const actPositionRows = toInsert.filter((x) => x.commandCode === "17");
|
||||||
// ส่งไปรักษาการ
|
|
||||||
const actPositionRows = toInsert.filter(
|
|
||||||
x => x.commandCode === "17"
|
|
||||||
);
|
|
||||||
// ส่งไปช่วยราชการ
|
// ส่งไปช่วยราชการ
|
||||||
const assistanceRows = toInsert.filter(
|
const assistanceRows = toInsert.filter((x) => x.commandCode === "18");
|
||||||
x => x.commandCode === "18"
|
|
||||||
);
|
|
||||||
|
|
||||||
if (salaryRows.length) {
|
if (salaryRows.length) {
|
||||||
await queryRunner.manager.insert(
|
await queryRunner.manager.insert(
|
||||||
|
|
@ -1407,14 +1399,14 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
salaryRows.map(({ id, ...data }) => ({
|
salaryRows.map(({ id, ...data }) => ({
|
||||||
...data,
|
...data,
|
||||||
...metaCreated,
|
...metaCreated,
|
||||||
}))
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (actPositionRows.length) {
|
if (actPositionRows.length > 0) {
|
||||||
await queryRunner.manager.insert(
|
await queryRunner.manager.insert(
|
||||||
ProfileActposition,
|
ProfileActposition,
|
||||||
actPositionRows.map(x => ({
|
actPositionRows.map((x) => ({
|
||||||
profileId: x.profileId,
|
profileId: x.profileId,
|
||||||
profileEmployeeId: x.profileEmployeeId,
|
profileEmployeeId: x.profileEmployeeId,
|
||||||
dateStart: x.commandDateAffect,
|
dateStart: x.commandDateAffect,
|
||||||
|
|
@ -1427,14 +1419,14 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
status: false,
|
status: false,
|
||||||
isDeleted: false,
|
isDeleted: false,
|
||||||
...metaCreated,
|
...metaCreated,
|
||||||
}))
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (assistanceRows.length) {
|
if (assistanceRows.length > 0) {
|
||||||
await queryRunner.manager.insert(
|
await queryRunner.manager.insert(
|
||||||
ProfileAssistance,
|
ProfileAssistance,
|
||||||
assistanceRows.map(x => ({
|
assistanceRows.map((x) => ({
|
||||||
profileId: x.profileId,
|
profileId: x.profileId,
|
||||||
profileEmployeeId: x.profileEmployeeId,
|
profileEmployeeId: x.profileEmployeeId,
|
||||||
agency: x.orgRoot,
|
agency: x.orgRoot,
|
||||||
|
|
@ -1448,7 +1440,7 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
status: "DONE",
|
status: "DONE",
|
||||||
isUpload: false,
|
isUpload: false,
|
||||||
...metaCreated,
|
...metaCreated,
|
||||||
}))
|
})),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1457,6 +1449,7 @@ export class ProfileSalaryTempController extends Controller {
|
||||||
if (backupTemp.length > 0) {
|
if (backupTemp.length > 0) {
|
||||||
const insertBackupTemp = toInsert.map(({ id, ...data }) => ({
|
const insertBackupTemp = toInsert.map(({ id, ...data }) => ({
|
||||||
...data,
|
...data,
|
||||||
|
salaryId: null,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await queryRunner.manager.insert(ProfileSalaryTemp, insertBackupTemp);
|
await queryRunner.manager.insert(ProfileSalaryTemp, insertBackupTemp);
|
||||||
|
|
|
||||||
|
|
@ -273,8 +273,9 @@ export class ProfileSalaryTemp extends EntityBase {
|
||||||
length: 40,
|
length: 40,
|
||||||
comment: "คีย์นอก(FK)ของตาราง profileSalary",
|
comment: "คีย์นอก(FK)ของตาราง profileSalary",
|
||||||
default: null,
|
default: null,
|
||||||
|
type: "varchar",
|
||||||
})
|
})
|
||||||
salaryId: string;
|
salaryId: string | null;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
|
|
@ -292,7 +293,7 @@ export class ProfileSalaryTemp extends EntityBase {
|
||||||
})
|
})
|
||||||
posNumCodeSitAbb: string;
|
posNumCodeSitAbb: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
length: 255,
|
length: 255,
|
||||||
comment: "ด้านทางการบริหาร",
|
comment: "ด้านทางการบริหาร",
|
||||||
|
|
|
||||||
|
|
@ -305,6 +305,22 @@ class CheckAuth {
|
||||||
public async PermissionOrgUserUpdate(req: RequestWithUser, system: string, profileId: string) {
|
public async PermissionOrgUserUpdate(req: RequestWithUser, system: string, profileId: string) {
|
||||||
return await this.PermissionOrgByUser(req, system, "UPDATE", profileId);
|
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;
|
export default CheckAuth;
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
|
||||||
});
|
});
|
||||||
// console.log("endDateFristRec", endDateFristRec.dateGovernment);
|
// console.log("endDateFristRec", endDateFristRec.dateGovernment);
|
||||||
|
|
||||||
const calculateDuration = (startDate: any, endDate: any , inclusive = false) => {
|
const calculateDuration = (startDate: any, endDate: any, inclusive = false) => {
|
||||||
if (inclusive) {
|
if (inclusive) {
|
||||||
endDate = new Date(endDate.getTime() + 86400000); // +1 วัน
|
endDate = new Date(endDate.getTime() + 86400000); // +1 วัน
|
||||||
}
|
}
|
||||||
|
|
@ -109,7 +109,7 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
|
||||||
// const firstStartDate = new Date(records[0].date);
|
// const firstStartDate = new Date(records[0].date);
|
||||||
const firstStartDate = !bkk
|
const firstStartDate = !bkk
|
||||||
? profile?.dateAppoint ? profile?.dateAppoint : new Date()
|
? profile?.dateAppoint ? profile?.dateAppoint : new Date()
|
||||||
: profile?.dateStart ? profile?.dateStart : new Date() ;
|
: profile?.dateStart ? profile?.dateStart : new Date();
|
||||||
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
|
const firstEndDate = endDateFristRec ? new Date(endDateFristRec.dateGovernment) : new Date();
|
||||||
|
|
||||||
// console.log("firstStartDate1", firstStartDate);
|
// console.log("firstStartDate1", firstStartDate);
|
||||||
|
|
@ -162,7 +162,7 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
|
||||||
}
|
}
|
||||||
|
|
||||||
//ตั้งแต่วันที่กลับมารับราขการไปจนถึงรวมถึงวันที่ปัจจุบัน
|
//ตั้งแต่วันที่กลับมารับราขการไปจนถึงรวมถึงวันที่ปัจจุบัน
|
||||||
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();
|
const daysInThisMonth = new Date(new Date().getFullYear(), new Date().getMonth() + 1, 0).getDate();
|
||||||
if (days >= daysInThisMonth) {
|
if (days >= daysInThisMonth) {
|
||||||
months += Math.floor(days / daysInThisMonth);
|
months += Math.floor(days / daysInThisMonth);
|
||||||
|
|
@ -192,10 +192,10 @@ export async function calculateGovAge(profileId: string, type: string, bkk?: boo
|
||||||
const finalAdjusted = adjustTotal(sumYears, sumMonths, sumDays);
|
const finalAdjusted = adjustTotal(sumYears, sumMonths, sumDays);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
year: finalAdjusted.years,
|
year: finalAdjusted.years,
|
||||||
month: finalAdjusted.months,
|
month: finalAdjusted.months,
|
||||||
day: finalAdjusted.days,
|
day: finalAdjusted.days,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function calculateRetireDate(birthDate: Date) {
|
export function calculateRetireDate(birthDate: Date) {
|
||||||
|
|
@ -262,10 +262,10 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
const draftRevision = await AppDataSource.getRepository(OrgRevision)
|
const draftRevision = await AppDataSource.getRepository(OrgRevision)
|
||||||
.createQueryBuilder("orgRevision")
|
.createQueryBuilder("orgRevision")
|
||||||
.where("orgRevision.orgRevisionIsDraft = true")
|
.where("orgRevision.orgRevisionIsDraft = true")
|
||||||
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
.andWhere("orgRevision.orgRevisionIsCurrent = false")
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
if (!currentRevision && !draftRevision) {
|
if (!currentRevision && !draftRevision) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -354,31 +354,31 @@ export async function removeProfileInOrganize(profileId: string, type: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function removePostMasterAct(profileId: string) {
|
export async function removePostMasterAct(profileId: string) {
|
||||||
const currentRevision = await AppDataSource.getRepository(OrgRevision)
|
const currentRevision = await AppDataSource.getRepository(OrgRevision)
|
||||||
.createQueryBuilder("orgRevision")
|
.createQueryBuilder("orgRevision")
|
||||||
.where("orgRevision.orgRevisionIsDraft = false")
|
.where("orgRevision.orgRevisionIsDraft = false")
|
||||||
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
.andWhere("orgRevision.orgRevisionIsCurrent = true")
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
if (!currentRevision) {
|
if (!currentRevision) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const findProfileInposMaster = await AppDataSource.getRepository(PosMaster)
|
const findProfileInposMaster = await AppDataSource.getRepository(PosMaster)
|
||||||
.createQueryBuilder("posMaster")
|
.createQueryBuilder("posMaster")
|
||||||
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: currentRevision?.id })
|
.where("posMaster.orgRevisionId = :orgRevisionId", { orgRevisionId: currentRevision?.id })
|
||||||
.andWhere("posMaster.current_holderId = :profileId", { profileId })
|
.andWhere("posMaster.current_holderId = :profileId", { profileId })
|
||||||
.getOne();
|
.getOne();
|
||||||
|
|
||||||
if (!findProfileInposMaster) {
|
if (!findProfileInposMaster) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const posMasterAct = await AppDataSource.getRepository(PosMasterAct)
|
const posMasterAct = await AppDataSource.getRepository(PosMasterAct)
|
||||||
.createQueryBuilder("posMasterAct")
|
.createQueryBuilder("posMasterAct")
|
||||||
.where("posMasterAct.posMasterChildId = :posMasterChildId", { posMasterChildId: findProfileInposMaster.id })
|
.where("posMasterAct.posMasterChildId = :posMasterChildId", { posMasterChildId: findProfileInposMaster.id })
|
||||||
.getMany();
|
.getMany();
|
||||||
await AppDataSource.getRepository(PosMasterAct).remove(posMasterAct);
|
await AppDataSource.getRepository(PosMasterAct).remove(posMasterAct);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function checkReturnCommandType(commandId: string) {
|
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) {
|
export async function checkQueueInProgress(queueName: string) {
|
||||||
const axios = require('axios');
|
const axios = require('axios');
|
||||||
// console.log("Checking queue in progress");
|
// console.log("Checking queue in progress");
|
||||||
const res = await axios.get(`${process.env.RABBIT_API_URL}/api/queues/%2F/${queueName}`, {
|
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 },
|
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(`Queue "${queueName}" has:`);
|
||||||
// console.log(` - ${q.messages_ready} messages ready`);
|
// console.log(` - ${q.messages_ready} messages ready`);
|
||||||
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
// console.log(` - ${q.messages_unacknowledged} messages in progress (unacked)`);
|
||||||
|
|
||||||
if (q.messages_unacknowledged > 0) {
|
if (q.messages_unacknowledged > 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function chunkArray(array: any, size: number) {
|
export function chunkArray(array: any, size: number) {
|
||||||
|
|
@ -733,3 +733,23 @@ export function commandTypePath(commandCode: string): string | null {
|
||||||
return 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
|
||||||
|
);
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue