add parent

This commit is contained in:
mamoss 2025-10-07 11:14:00 +07:00
parent 4c16c9859a
commit fd17f366b8
6 changed files with 164 additions and 366 deletions

View file

@ -1152,26 +1152,6 @@ export class OrganizationController extends Controller {
*/ */
@Get("super-admin/{id}") @Get("super-admin/{id}")
async detailSuperAdmin(@Path() id: string, @Request() request: RequestWithUser) { async detailSuperAdmin(@Path() id: string, @Request() request: RequestWithUser) {
// let _data: any = {
// root: null,
// child1: null,
// child2: null,
// child3: null,
// child4: null,
// };
// const orgRevision = await this.orgRevisionRepository.findOne({ where: { id } });
// if (!orgRevision) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
// }
// if (!request.user.role.includes("SUPER_ADMIN")) {
// if (orgRevision.orgRevisionIsDraft == true && orgRevision.orgRevisionIsCurrent == false) {
// _data = await this.listAuthSysOrgFuncByRevisionIdN(request, "SYS_ORG", orgRevision.id);
// } else {
// _data = await this.listAuthSysOrgFuncByRevisionIdC(request, "SYS_ORG", orgRevision.id);
// }
// }
const orgRevision = await this.orgRevisionRepository.findOne({ const orgRevision = await this.orgRevisionRepository.findOne({
where: { id: id }, where: { id: id },
relations: ["posMasters"], relations: ["posMasters"],
@ -7527,208 +7507,7 @@ export class OrganizationController extends Controller {
const check = orgRevision.orgRoots.find((x) => x.isDeputy == true); const check = orgRevision.orgRoots.find((x) => x.isDeputy == true);
return new HttpSuccess(check != null); return new HttpSuccess(check != null);
} }
public async listAuthSysOrgFuncByRevisionIdN(
request: RequestWithUser,
system: string,
revisionId: string,
) {
let profile = await this.profileRepo.findOne({
where: {
keycloak: request.user.sub,
},
relations: ["next_holders", "next_holders.authRole", "next_holders.authRole.authRoles"],
});
let data: any = {
root: [null],
child1: [null],
child2: [null],
child3: [null],
child4: [null],
};
if (!profile) {
return {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
}
let attrOwnership =
profile?.next_holders
.filter((x) => x.orgRevisionId == revisionId)[0]
?.authRole?.authRoles?.filter((x) => x.authSysId == system)[0]?.attrOwnership || null;
let attrPrivilege =
profile?.next_holders
.filter((x) => x.orgRevisionId == revisionId)[0]
?.authRole?.authRoles?.filter((x) => x.authSysId == system)[0]?.attrPrivilege || null;
const posMaster = await this.posMasterRepository.findOne({
where: {
next_holderId: profile.id,
orgRevisionId: revisionId,
},
});
if (!posMaster) {
data = {
root: [null],
child1: [null],
child2: [null],
child3: [null],
child4: [null],
};
} else if (attrOwnership == "OWNER") {
data = {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
} else if (attrPrivilege == "ROOT") {
data = {
root: [posMaster.orgRootId],
child1: null,
child2: null,
child3: null,
child4: null,
privilege: "ROOT",
};
} else if (attrPrivilege == "CHILD") {
let node = 4;
if (posMaster.orgChild1Id == null) {
node = 0;
} else if (posMaster.orgChild2Id == null) {
node = 1;
} else if (posMaster.orgChild3Id == null) {
node = 2;
} else if (posMaster.orgChild4Id == null) {
node = 3;
}
data = {
root: node >= 0 ? [posMaster.orgRootId] : null,
child1: node >= 1 ? [posMaster.orgChild1Id] : null,
child2: node >= 2 ? [posMaster.orgChild2Id] : null,
child3: node >= 3 ? [posMaster.orgChild3Id] : null,
child4: node >= 4 ? [posMaster.orgChild4Id] : null,
};
} else if (attrPrivilege == "NORMAL") {
data = {
root: [posMaster.orgRootId],
child1: [posMaster.orgChild1Id],
child2: [posMaster.orgChild2Id],
child3: [posMaster.orgChild3Id],
child4: [posMaster.orgChild4Id],
};
} else if (attrPrivilege == "SPECIFIC") {
}
return data;
}
public async listAuthSysOrgFuncByRevisionIdC(
request: RequestWithUser,
system: string,
revisionId: string,
) {
let profile = await this.profileRepo.findOne({
where: {
keycloak: request.user.sub,
},
relations: [
"current_holders",
"current_holders.authRole",
"current_holders.authRole.authRoles",
],
});
let data: any = {
root: [null],
child1: [null],
child2: [null],
child3: [null],
child4: [null],
};
if (!profile) {
return {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
}
let attrOwnership =
profile?.current_holders
.filter((x) => x.orgRevisionId == revisionId)[0]
?.authRole?.authRoles?.filter((x) => x.authSysId == system)[0]?.attrOwnership || null;
let attrPrivilege =
profile?.current_holders
.filter((x) => x.orgRevisionId == revisionId)[0]
?.authRole?.authRoles?.filter((x) => x.authSysId == system)[0]?.attrPrivilege || null;
const posMaster = await this.posMasterRepository.findOne({
where: {
next_holderId: profile.id,
orgRevisionId: revisionId,
},
});
if (!posMaster) {
data = {
root: [null],
child1: [null],
child2: [null],
child3: [null],
child4: [null],
};
} else if (attrOwnership == "OWNER") {
data = {
root: null,
child1: null,
child2: null,
child3: null,
child4: null,
};
} else if (attrPrivilege == "ROOT") {
data = {
root: [posMaster.orgRootId],
child1: null,
child2: null,
child3: null,
child4: null,
privilege: "ROOT",
};
} else if (attrPrivilege == "CHILD") {
let node = 4;
if (posMaster.orgChild1Id == null) {
node = 0;
} else if (posMaster.orgChild2Id == null) {
node = 1;
} else if (posMaster.orgChild3Id == null) {
node = 2;
} else if (posMaster.orgChild4Id == null) {
node = 3;
}
data = {
root: node >= 0 ? [posMaster.orgRootId] : null,
child1: node >= 1 ? [posMaster.orgChild1Id] : null,
child2: node >= 2 ? [posMaster.orgChild2Id] : null,
child3: node >= 3 ? [posMaster.orgChild3Id] : null,
child4: node >= 4 ? [posMaster.orgChild4Id] : null,
};
} else if (attrPrivilege == "NORMAL") {
data = {
root: [posMaster.orgRootId],
child1: [posMaster.orgChild1Id],
child2: [posMaster.orgChild2Id],
child3: [posMaster.orgChild3Id],
child4: [posMaster.orgChild4Id],
};
} else if (attrPrivilege == "SPECIFIC") {
}
return data;
}
/** /**
* API 1 * API 1
* *

View file

@ -120,12 +120,13 @@ export class OrganizationDotnetController extends Controller {
break; break;
} }
conditionParams = { nodeId: body.nodeId }; conditionParams = { nodeId: body.nodeId };
} } else if (body.role === "ROOT") {
else if (body.role === "ROOT") {
condition = "orgRoot.ancestorDNA = :nodeId"; condition = "orgRoot.ancestorDNA = :nodeId";
conditionParams = { nodeId: body.nodeId }; conditionParams = { nodeId: body.nodeId };
} } else if (body.role === "PARENT") {
else if (body.role === "NORMAL") { condition = "orgChild1.ancestorDNA = :nodeId";
conditionParams = { nodeId: body.nodeId };
} else if (body.role === "NORMAL") {
switch (body.node) { switch (body.node) {
case 0: case 0:
condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL"; condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL";
@ -150,7 +151,7 @@ export class OrganizationDotnetController extends Controller {
} }
const findRevision = await this.orgRevisionRepo.findOne({ const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
if (!findRevision) { if (!findRevision) {
throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision"); throw new HttpError(HttpStatus.NOT_FOUND, "not found. OrgRevision");
@ -180,8 +181,8 @@ export class OrganizationDotnetController extends Controller {
}), }),
) )
.andWhere(condition, conditionParams) .andWhere(condition, conditionParams)
.getMany() .getMany();
return new HttpSuccess(profiles); return new HttpSuccess(profiles);
} }
@ -259,12 +260,13 @@ export class OrganizationDotnetController extends Controller {
break; break;
} }
conditionParams = { nodeId: body.nodeId }; conditionParams = { nodeId: body.nodeId };
} } else if (body.role === "ROOT") {
else if (body.role === "ROOT") {
condition = "orgRoot.ancestorDNA = :nodeId"; condition = "orgRoot.ancestorDNA = :nodeId";
conditionParams = { nodeId: body.nodeId }; conditionParams = { nodeId: body.nodeId };
} } else if (body.role === "PARENT") {
else if (body.role === "NORMAL") { condition = "orgChild1.ancestorDNA = :nodeId";
conditionParams = { nodeId: body.nodeId };
} else if (body.role === "NORMAL") {
switch (body.node) { switch (body.node) {
case 0: case 0:
condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL"; condition = "orgRoot.ancestorDNA = :nodeId AND current_holders.orgChild1 IS NULL";
@ -321,7 +323,7 @@ export class OrganizationDotnetController extends Controller {
) )
.andWhere(condition, conditionParams) .andWhere(condition, conditionParams)
.orderBy("profileSalary.order", "DESC") .orderBy("profileSalary.order", "DESC")
.getMany() .getMany();
const profileEmp_ = await Promise.all( const profileEmp_ = await Promise.all(
profileEmp.map((item: ProfileEmployee) => { profileEmp.map((item: ProfileEmployee) => {
@ -693,10 +695,10 @@ export class OrganizationDotnetController extends Controller {
} }
} }
} }
let positionLeaveName = let positionLeaveName =
profile.posType == null && profile.posLevel == null profile.posType == null && profile.posLevel == null
? "" ? ""
: `${profile.posType?.posTypeShortName ?? ""} ${profile.posLevel?.posLevelName ?? ""}` : `${profile.posType?.posTypeShortName ?? ""} ${profile.posLevel?.posLevelName ?? ""}`;
const _profileCurrent = profile?.current_holders?.find( const _profileCurrent = profile?.current_holders?.find(
(x) => (x) =>
@ -4077,27 +4079,27 @@ export class OrganizationDotnetController extends Controller {
// }; // };
// } // }
// } else { // } else {
if (body.node === 0) { if (body.node === 0) {
typeCondition = { typeCondition = {
orgRootId: body.nodeId, orgRootId: body.nodeId,
}; };
} else if (body.node === 1) { } else if (body.node === 1) {
typeCondition = { typeCondition = {
orgChild1Id: body.nodeId, orgChild1Id: body.nodeId,
}; };
} else if (body.node === 2) { } else if (body.node === 2) {
typeCondition = { typeCondition = {
orgChild2Id: body.nodeId, orgChild2Id: body.nodeId,
}; };
} else if (body.node === 3) { } else if (body.node === 3) {
typeCondition = { typeCondition = {
orgChild3Id: body.nodeId, orgChild3Id: body.nodeId,
}; };
} else if (body.node === 4) { } else if (body.node === 4) {
typeCondition = { typeCondition = {
orgChild4Id: body.nodeId, orgChild4Id: body.nodeId,
}; };
} }
// } // }
let profile = await this.profileRepo.find({ let profile = await this.profileRepo.find({
where: { keycloak: Not(IsNull()) || Not(""), isLeave: false, current_holders: typeCondition }, where: { keycloak: Not(IsNull()) || Not(""), isLeave: false, current_holders: typeCondition },
@ -4123,10 +4125,7 @@ export class OrganizationDotnetController extends Controller {
// isLeave: false, // isLeave: false,
current_holders: typeCondition, current_holders: typeCondition,
// isRetirement: true, // isRetirement: true,
dateRetire: And( dateRetire: And(Not(IsNull()), Between(startOfYear, endOfYear)),
Not(IsNull()),
Between(startOfYear, endOfYear)
)
}, },
relations: [ relations: [
"posType", "posType",
@ -4397,15 +4396,15 @@ export class OrganizationDotnetController extends Controller {
}, },
) { ) {
let findRevision = await this.orgRevisionRepo.findOne({ let findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
switch (body.node) { switch (body.node) {
case 0: case 0:
let orgRoot = await this.orgRootRepo.findOne({ let orgRoot = await this.orgRootRepo.findOne({
where: { where: {
id: body.nodeId, id: body.nodeId,
orgRevisionId: findRevision?.id orgRevisionId: findRevision?.id,
} },
}); });
return new HttpSuccess({ return new HttpSuccess({
rootName: orgRoot?.orgRootName ?? null, rootName: orgRoot?.orgRootName ?? null,
@ -4418,10 +4417,10 @@ export class OrganizationDotnetController extends Controller {
case 1: case 1:
let orgChild1 = await this.orgChild1Repo.findOne({ let orgChild1 = await this.orgChild1Repo.findOne({
relations: ["orgRoot"], relations: ["orgRoot"],
where: { where: {
id: body.nodeId, id: body.nodeId,
orgRevisionId: findRevision?.id orgRevisionId: findRevision?.id,
} },
}); });
return new HttpSuccess({ return new HttpSuccess({
rootName: orgChild1?.orgRoot.orgRootName ?? null, rootName: orgChild1?.orgRoot.orgRootName ?? null,
@ -4434,10 +4433,10 @@ export class OrganizationDotnetController extends Controller {
case 2: case 2:
let orgChild2 = await this.orgChild2Repo.findOne({ let orgChild2 = await this.orgChild2Repo.findOne({
relations: ["orgRoot", "orgChild1"], relations: ["orgRoot", "orgChild1"],
where: { where: {
id: body.nodeId, id: body.nodeId,
orgRevisionId: findRevision?.id orgRevisionId: findRevision?.id,
} },
}); });
return new HttpSuccess({ return new HttpSuccess({
rootName: orgChild2?.orgRoot.orgRootName ?? null, rootName: orgChild2?.orgRoot.orgRootName ?? null,
@ -4450,10 +4449,10 @@ export class OrganizationDotnetController extends Controller {
case 3: case 3:
let orgChild3 = await this.orgChild3Repo.findOne({ let orgChild3 = await this.orgChild3Repo.findOne({
relations: ["orgRoot", "orgChild1", "orgChild2"], relations: ["orgRoot", "orgChild1", "orgChild2"],
where: { where: {
id: body.nodeId, id: body.nodeId,
orgRevisionId: findRevision?.id orgRevisionId: findRevision?.id,
} },
}); });
return new HttpSuccess({ return new HttpSuccess({
rootName: orgChild3?.orgRoot.orgRootName ?? null, rootName: orgChild3?.orgRoot.orgRootName ?? null,
@ -4466,10 +4465,10 @@ export class OrganizationDotnetController extends Controller {
case 4: case 4:
let orgChild4 = await this.orgChild4Repo.findOne({ let orgChild4 = await this.orgChild4Repo.findOne({
relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"], relations: ["orgRoot", "orgChild1", "orgChild2", "orgChild3"],
where: { where: {
id: body.nodeId, id: body.nodeId,
orgRevisionId: findRevision?.id orgRevisionId: findRevision?.id,
} },
}); });
return new HttpSuccess({ return new HttpSuccess({
rootName: orgChild4?.orgRoot.orgRootName ?? null, rootName: orgChild4?.orgRoot.orgRootName ?? null,
@ -4486,7 +4485,7 @@ export class OrganizationDotnetController extends Controller {
child2Name: null, child2Name: null,
child3Name: null, child3Name: null,
child4Name: null, child4Name: null,
});; });
} }
} }
@ -4506,87 +4505,87 @@ export class OrganizationDotnetController extends Controller {
role: string; role: string;
isRetirement?: boolean; isRetirement?: boolean;
revisionId?: string; revisionId?: string;
reqNode?: number; reqNode?: number;
reqNodeId?: string; reqNodeId?: string;
}, },
) { ) {
let typeCondition: any = {}; let typeCondition: any = {};
if (body.role === "CHILD") { if (body.role === "CHILD" || body.role === "PARENT" || body.role === "ROOT") {
switch (body.node) { switch (body.node) {
case 0: case 0:
typeCondition = { typeCondition = {
orgRoot: { orgRoot: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 1: case 1:
typeCondition = { typeCondition = {
orgChild1: { orgChild1: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 2: case 2:
typeCondition = { typeCondition = {
orgChild2: { orgChild2: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 3: case 3:
typeCondition = { typeCondition = {
orgChild3: { orgChild3: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 4: case 4:
typeCondition = { typeCondition = {
orgChild4: { orgChild4: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
default: default:
typeCondition = {}; typeCondition = {};
break; break;
} }
} else if (body.role === "ROOT" || body.role === "OWNER") { } else if (body.role === "OWNER") {
switch (body.reqNode) { switch (body.reqNode) {
case 0: case 0:
typeCondition = { typeCondition = {
orgRoot: { orgRoot: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 1: case 1:
typeCondition = { typeCondition = {
orgChild1: { orgChild1: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 2: case 2:
typeCondition = { typeCondition = {
orgChild2: { orgChild2: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 3: case 3:
typeCondition = { typeCondition = {
orgChild3: { orgChild3: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 4: case 4:
typeCondition = { typeCondition = {
orgChild4: { orgChild4: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
default: default:
@ -4598,39 +4597,39 @@ export class OrganizationDotnetController extends Controller {
case 0: case 0:
typeCondition = { typeCondition = {
orgRoot: { orgRoot: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild1: IsNull() orgChild1: IsNull(),
}; };
break; break;
case 1: case 1:
typeCondition = { typeCondition = {
orgChild1: { orgChild1: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild2: IsNull() orgChild2: IsNull(),
}; };
break; break;
case 2: case 2:
typeCondition = { typeCondition = {
orgChild2: { orgChild2: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild3: IsNull() orgChild3: IsNull(),
}; };
break; break;
case 3: case 3:
typeCondition = { typeCondition = {
orgChild3: { orgChild3: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild4: IsNull() orgChild4: IsNull(),
}; };
break; break;
case 4: case 4:
typeCondition = { typeCondition = {
orgChild4: { orgChild4: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
}; };
break; break;
@ -4670,8 +4669,8 @@ export class OrganizationDotnetController extends Controller {
orgChild4Order: "ASC", orgChild4Order: "ASC",
}, },
posMasterNo: "ASC", posMasterNo: "ASC",
} },
} },
}); });
if (body.isRetirement) { if (body.isRetirement) {
profile = await this.profileRepo.find({ profile = await this.profileRepo.find({
@ -4693,7 +4692,7 @@ export class OrganizationDotnetController extends Controller {
}); });
} }
let findRevision = await this.orgRevisionRepo.findOne({ let findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
if (body.revisionId) { if (body.revisionId) {
@ -4703,7 +4702,7 @@ export class OrganizationDotnetController extends Controller {
} }
const profile_ = await Promise.all( const profile_ = await Promise.all(
profile.map(async(item: Profile) => { profile.map(async (item: Profile) => {
const shortName = const shortName =
item.current_holders.length == 0 item.current_holders.length == 0
? null ? null
@ -4747,8 +4746,8 @@ export class OrganizationDotnetController extends Controller {
let _posMaster = await this.posMasterRepository.findOne({ let _posMaster = await this.posMasterRepository.findOne({
where: { where: {
orgRevisionId: findRevision?.id, orgRevisionId: findRevision?.id,
current_holderId: item.id current_holderId: item.id,
} },
}); });
return { return {
@ -4769,7 +4768,7 @@ export class OrganizationDotnetController extends Controller {
orgChild1Id: _posMaster?.orgChild1Id, orgChild1Id: _posMaster?.orgChild1Id,
orgChild2Id: _posMaster?.orgChild2Id, orgChild2Id: _posMaster?.orgChild2Id,
orgChild3Id: _posMaster?.orgChild3Id, orgChild3Id: _posMaster?.orgChild3Id,
orgChild4Id: _posMaster?.orgChild4Id orgChild4Id: _posMaster?.orgChild4Id,
}; };
}), }),
); );
@ -5101,46 +5100,46 @@ export class OrganizationDotnetController extends Controller {
role: string; role: string;
isRetirement?: boolean; isRetirement?: boolean;
revisionId?: string; revisionId?: string;
reqNode?: number; reqNode?: number;
reqNodeId?: string; reqNodeId?: string;
}, },
) { ) {
let typeCondition: any = {}; let typeCondition: any = {};
if (body.role === "CHILD") { if (body.role === "CHILD" || body.role === "PARENT" || body.role === "ROOT") {
switch (body.node) { switch (body.node) {
case 0: case 0:
typeCondition = { typeCondition = {
orgRoot: { orgRoot: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 1: case 1:
typeCondition = { typeCondition = {
orgChild1: { orgChild1: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 2: case 2:
typeCondition = { typeCondition = {
orgChild2: { orgChild2: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 3: case 3:
typeCondition = { typeCondition = {
orgChild3: { orgChild3: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case 4: case 4:
typeCondition = { typeCondition = {
orgChild4: { orgChild4: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
} },
}; };
break; break;
case null: case null:
@ -5150,41 +5149,41 @@ export class OrganizationDotnetController extends Controller {
typeCondition = {}; typeCondition = {};
break; break;
} }
} else if (body.role === "ROOT" || body.role === "OWNER") { } else if (body.role === "OWNER") {
switch (body.reqNode) { switch (body.reqNode) {
case 0: case 0:
typeCondition = { typeCondition = {
orgRoot: { orgRoot: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 1: case 1:
typeCondition = { typeCondition = {
orgChild1: { orgChild1: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 2: case 2:
typeCondition = { typeCondition = {
orgChild2: { orgChild2: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 3: case 3:
typeCondition = { typeCondition = {
orgChild3: { orgChild3: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
case 4: case 4:
typeCondition = { typeCondition = {
orgChild4: { orgChild4: {
id: body.reqNodeId id: body.reqNodeId,
} },
}; };
break; break;
default: default:
@ -5196,39 +5195,39 @@ export class OrganizationDotnetController extends Controller {
case 0: case 0:
typeCondition = { typeCondition = {
orgRoot: { orgRoot: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild1: IsNull() orgChild1: IsNull(),
}; };
break; break;
case 1: case 1:
typeCondition = { typeCondition = {
orgChild1: { orgChild1: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild2: IsNull() orgChild2: IsNull(),
}; };
break; break;
case 2: case 2:
typeCondition = { typeCondition = {
orgChild2: { orgChild2: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild3: IsNull() orgChild3: IsNull(),
}; };
break; break;
case 3: case 3:
typeCondition = { typeCondition = {
orgChild3: { orgChild3: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
orgChild4: IsNull() orgChild4: IsNull(),
}; };
break; break;
case 4: case 4:
typeCondition = { typeCondition = {
orgChild4: { orgChild4: {
ancestorDNA: body.nodeId ancestorDNA: body.nodeId,
}, },
}; };
break; break;
@ -5268,8 +5267,8 @@ export class OrganizationDotnetController extends Controller {
orgChild4Order: "ASC", orgChild4Order: "ASC",
}, },
posMasterNo: "ASC", posMasterNo: "ASC",
} },
} },
}); });
if (body.isRetirement) { if (body.isRetirement) {
profile = await this.profileEmpRepo.find({ profile = await this.profileEmpRepo.find({
@ -5291,7 +5290,7 @@ export class OrganizationDotnetController extends Controller {
}); });
} }
let findRevision = await this.orgRevisionRepo.findOne({ let findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false } where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
}); });
if (body.revisionId) { if (body.revisionId) {
@ -5301,7 +5300,7 @@ export class OrganizationDotnetController extends Controller {
} }
const profile_ = await Promise.all( const profile_ = await Promise.all(
profile.map(async(item: ProfileEmployee) => { profile.map(async (item: ProfileEmployee) => {
const shortName = const shortName =
item.current_holders.length == 0 item.current_holders.length == 0
? null ? null
@ -5345,8 +5344,8 @@ export class OrganizationDotnetController extends Controller {
let _posMaster = await this.empPosMasterRepository.findOne({ let _posMaster = await this.empPosMasterRepository.findOne({
where: { where: {
orgRevisionId: findRevision?.id, orgRevisionId: findRevision?.id,
current_holderId: item.id current_holderId: item.id,
} },
}); });
return { return {
@ -5360,9 +5359,10 @@ export class OrganizationDotnetController extends Controller {
keycloak: item.keycloak, keycloak: item.keycloak,
posNo: shortName, posNo: shortName,
position: item.position, position: item.position,
positionLevel: item.posType?.posTypeShortName && item.posLevel?.posLevelName positionLevel:
? `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}` item.posType?.posTypeShortName && item.posLevel?.posLevelName
: null, ? `${item.posType?.posTypeShortName} ${item.posLevel?.posLevelName}`
: null,
positionType: item.posType?.posTypeName ?? null, positionType: item.posType?.posTypeName ?? null,
oc: Oc, oc: Oc,
orgRootId: _posMaster?.orgRootId, orgRootId: _posMaster?.orgRootId,
@ -5580,7 +5580,7 @@ export class OrganizationDotnetController extends Controller {
} }
const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [ const position = await AppDataSource.query("CALL GetProfileEmployeeSalaryPosition(?, ?)", [
profile.id, profile.id,
_currentDate _currentDate,
]); ]);
const _position = position.length > 0 ? position[0] : []; const _position = position.length > 0 ? position[0] : [];
@ -5692,11 +5692,13 @@ export class OrganizationDotnetController extends Controller {
} }
} }
if (profile && profile?.isLeave) { if (profile && profile?.isLeave) {
_currentDate = profile && profile.leaveDate _currentDate =
? Extension.toDateOnlyString(profile.leaveDate) profile && profile.leaveDate ? Extension.toDateOnlyString(profile.leaveDate) : _currentDate;
: _currentDate
} }
const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [profile.id, _currentDate]); const position = await AppDataSource.query("CALL GetProfileSalaryPosition(?, ?)", [
profile.id,
_currentDate,
]);
const _position = position.length > 0 ? position[0] : []; const _position = position.length > 0 ? position[0] : [];
const mapProfile = { const mapProfile = {

View file

@ -732,6 +732,14 @@ export class PermissionController extends Controller {
child3: null, child3: null,
child4: null, child4: null,
}; };
} else if (privilege == "PARENT") {
data = {
root: [x.orgRootId],
child1: [x.orgChild1Id],
child2: null,
child3: null,
child4: null,
};
} else if (privilege == "CHILD") { } else if (privilege == "CHILD") {
data = { data = {
root: node >= 0 ? [x.orgRootId] : null, root: node >= 0 ? [x.orgRootId] : null,

View file

@ -911,6 +911,7 @@ export class KeycloakController extends Controller {
// keycloak: IsNull(), // keycloak: IsNull(),
isLeave: false, isLeave: false,
}, },
order: { citizenId: "ASC" },
relations: ["roleKeycloaks"], relations: ["roleKeycloaks"],
}); });
@ -924,12 +925,11 @@ export class KeycloakController extends Controller {
}); });
// Process แบบ batch เพื่อลดการเรียก API ทีละตัว // Process แบบ batch เพื่อลดการเรียก API ทีละตัว
const batchSize = 10; const batchSize = 100;
const batches = []; const batches = [];
for (let i = 0; i < profiles.length; i += batchSize) { for (let i = 0; i < profiles.length; i += batchSize) {
batches.push(profiles.slice(i, i + batchSize)); batches.push(profiles.slice(i, i + batchSize));
} }
for (const batch of batches) { for (const batch of batches) {
await Promise.all( await Promise.all(
batch.map(async (_item) => { batch.map(async (_item) => {

View file

@ -94,6 +94,15 @@ class CheckAuth {
child4: null, child4: null,
privilege: "ROOT", privilege: "ROOT",
}; };
} else if (privilege == "PARENT") {
data = {
root: [x.orgRootId],
child1: [x.orgChild1Id],
child2: null,
child3: null,
child4: null,
privilege: "PARENT",
};
} else if (privilege == "CHILD") { } else if (privilege == "CHILD") {
data = { data = {
root: node >= 0 ? [x.orgRootId] : null, root: node >= 0 ? [x.orgRootId] : null,

View file

@ -56,7 +56,7 @@ export async function getToken() {
if (data && data.access_token) { if (data && data.access_token) {
token = data.access_token; token = data.access_token;
} }
console.log(`token: ${token}`);
return token; return token;
} }