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}")
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({
where: { id: id },
relations: ["posMasters"],
@ -7527,208 +7507,7 @@ export class OrganizationController extends Controller {
const check = orgRevision.orgRoots.find((x) => x.isDeputy == true);
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
*