This commit is contained in:
Warunee Tamkoo 2026-02-06 21:46:41 +07:00
commit 3177ffc42f
5 changed files with 265 additions and 188 deletions

View file

@ -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,7 +5670,9 @@ 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
? []
: await Promise.all(
orgRoot.posMasters orgRoot.posMasters
.filter( .filter(
(x) => (x) =>
@ -5681,7 +5720,9 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: cannotViewChild1PosMaster
? []
: await Promise.all(
orgChild1.posMasters orgChild1.posMasters
.filter( .filter(
(x) => (x) =>
@ -5737,7 +5778,9 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: cannotViewChild2PosMaster
? []
: await Promise.all(
orgChild2.posMasters orgChild2.posMasters
.filter( .filter(
(x) => (x) =>
@ -5800,7 +5843,9 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: cannotViewChild3PosMaster
? []
: await Promise.all(
orgChild3.posMasters orgChild3.posMasters
.filter( .filter(
(x) => (x) =>
@ -5870,7 +5915,9 @@ export class OrganizationController extends Controller {
"00" + "00" +
" " + " " +
orgRoot.orgRootShortName, orgRoot.orgRootShortName,
posMaster: await Promise.all( posMaster: cannotViewChild4PosMaster
? []
: await Promise.all(
orgChild4.posMasters orgChild4.posMasters
.filter( .filter(
(x) => (x) =>

View file

@ -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( const actPositionRows = toInsert.filter((x) => x.commandCode === "17");
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);

View file

@ -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,

View file

@ -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;

View file

@ -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
);
}