draft org

This commit is contained in:
kittapath 2024-11-18 14:34:01 +07:00
parent 1d5c285003
commit 58c371b888
2 changed files with 577 additions and 67 deletions

View file

@ -321,7 +321,9 @@ export class OrganizationController extends Controller {
await this.child1Repository.save(data1);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
//create posmaster
await Promise.all(
@ -402,7 +404,9 @@ export class OrganizationController extends Controller {
await this.child2Repository.save(data2);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
//create posmaster
await Promise.all(
@ -485,7 +489,9 @@ export class OrganizationController extends Controller {
await this.child3Repository.save(data3);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
//create posmaster
await Promise.all(
@ -572,8 +578,11 @@ export class OrganizationController extends Controller {
await this.child4Repository.save(data4);
if (
requestBody.typeDraft.toUpperCase() == "ORG_POSITION" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON"
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_ROLE" ||
requestBody.typeDraft.toUpperCase() == "ORG_POSITION_PERSON_ROLE"
) {
//create posmaster
await Promise.all(
_orgPosMaster
.filter((x: PosMaster) => x.orgChild4Id == data4Id)

View file

@ -1074,6 +1074,36 @@ export class OrganizationDotnetController extends Controller {
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.orgChild4Name ?? null,
rootId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRootId ?? null,
child1Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1Id ?? null,
child2Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2Id ?? null,
child3Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3Id ?? null,
child4Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4Id ?? null,
commander: fullname,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
@ -1309,6 +1339,36 @@ export class OrganizationDotnetController extends Controller {
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.orgChild4Name ?? null,
rootId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRootId ?? null,
child1Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1Id ?? null,
child2Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2Id ?? null,
child3Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3Id ?? null,
child4Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4Id ?? null,
commander: fullname,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
@ -1329,12 +1389,19 @@ export class OrganizationDotnetController extends Controller {
@Get("citizenId/{citizenId}")
async GetProfileByCitizenIdAsync(@Path() citizenId: string) {
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
relations: [
"posLevel",
"posType",
"profileSalary",
"profileInsignias",
"current_holders",
"current_holders.orgRevision",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { citizenId: citizenId },
order: {
profileSalary: {
@ -1345,14 +1412,22 @@ export class OrganizationDotnetController extends Controller {
},
},
});
if (!profile) {
const _profile = await this.profileEmpRepo.findOne({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
const profile = await this.profileEmpRepo.findOne({
relations: [
"posLevel",
"posType",
"profileSalary",
"profileInsignias",
"current_holders",
"current_holders.orgRevision",
"current_holders.orgRoot",
"current_holders.orgChild1",
"current_holders.orgChild2",
"current_holders.orgChild3",
"current_holders.orgChild4",
],
where: { citizenId: citizenId },
order: {
profileSalary: {
@ -1363,57 +1438,421 @@ export class OrganizationDotnetController extends Controller {
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const _mapProfile = {
id: _profile.id,
avatar: _profile.avatar,
avatarName: _profile.avatarName,
rank: _profile.rank,
prefix: _profile.prefix,
firstName: _profile.firstName,
lastName: _profile.lastName,
citizenId: _profile.citizenId,
position: _profile.position,
posLevelId: _profile.posLevelId,
email: _profile.email,
phone: _profile.phone,
keycloak: _profile.keycloak,
isProbation: _profile.isProbation,
isLeave: _profile.isLeave,
leaveReason: _profile.leaveReason,
dateRetire: _profile.dateRetire,
dateAppoint: _profile.dateAppoint,
dateRetireLaw: _profile.dateRetireLaw,
dateStart: _profile.dateStart,
govAgeAbsent: _profile.govAgeAbsent,
govAgePlus: _profile.govAgePlus,
birthDate: _profile.birthDate,
reasonSameDate: _profile.reasonSameDate,
telephoneNumber: _profile.telephoneNumber,
nationality: _profile.nationality,
gender: _profile.gender,
relationship: _profile.relationship,
religion: _profile.religion,
bloodGroup: _profile.bloodGroup,
registrationAddress: _profile.registrationAddress,
registrationProvinceId: _profile.registrationProvinceId,
registrationDistrictId: _profile.registrationDistrictId,
registrationSubDistrictId: _profile.registrationSubDistrictId,
registrationZipCode: _profile.registrationZipCode,
currentAddress: _profile.currentAddress,
currentProvinceId: _profile.currentProvinceId,
currentSubDistrictId: _profile.currentSubDistrictId,
currentZipCode: _profile.currentZipCode,
dutyTimeId: null,
dutyTimeEffectiveDate: null,
posLevel: _profile.posLevel ? _profile.posLevel : null,
posType: _profile.posType ? _profile.posType : null,
profileSalary: _profile.profileSalary,
profileInsignia: _profile.profileInsignias,
const org = {
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.id ?? null,
child1:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1?.id ?? null,
child2:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2?.id ?? null,
child3:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3?.id ?? null,
child4:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.id ?? null,
};
let fullname = "";
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: org?.child4 ?? "",
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
orgRootId: org?.root ?? "",
orgChild1Id: IsNull(),
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
fullname = "";
}
}
}
}
}
const mapProfile = {
id: profile.id,
avatar: profile.avatar,
avatarName: profile.avatarName,
rank: profile.rank,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
citizenId: profile.citizenId,
position: profile.position,
posLevelId: profile.posLevelId,
email: profile.email,
phone: profile.phone,
keycloak: profile.keycloak,
isProbation: profile.isProbation,
isLeave: profile.isLeave,
leaveReason: profile.leaveReason,
dateRetire: profile.dateRetire,
dateAppoint: profile.dateAppoint,
dateRetireLaw: profile.dateRetireLaw,
dateStart: profile.dateStart,
govAgeAbsent: profile.govAgeAbsent,
govAgePlus: profile.govAgePlus,
birthDate: profile.birthDate,
reasonSameDate: profile.reasonSameDate,
telephoneNumber: profile.telephoneNumber,
nationality: profile.nationality,
gender: profile.gender,
relationship: profile.relationship,
religion: profile.religion,
bloodGroup: profile.bloodGroup,
registrationAddress: profile.registrationAddress,
registrationProvinceId: profile.registrationProvinceId,
registrationDistrictId: profile.registrationDistrictId,
registrationSubDistrictId: profile.registrationSubDistrictId,
registrationZipCode: profile.registrationZipCode,
currentAddress: profile.currentAddress,
currentProvinceId: profile.currentProvinceId,
currentSubDistrictId: profile.currentSubDistrictId,
currentZipCode: profile.currentZipCode,
dutyTimeId: profile.dutyTimeId,
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
amountd: profile.amount,
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.orgRootName ?? null,
child1:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1?.orgChild1Name ?? null,
child2:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2?.orgChild2Name ?? null,
child3:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3?.orgChild3Name ?? null,
child4:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.orgChild4Name ?? null,
rootId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRootId ?? null,
child1Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1Id ?? null,
child2Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2Id ?? null,
child3Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3Id ?? null,
child4Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4Id ?? null,
commander: fullname,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
profileType: "EMPLOYEE",
};
return new HttpSuccess(_mapProfile);
return new HttpSuccess(mapProfile);
}
const org = {
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.id ?? null,
child1:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1?.id ?? null,
child2:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2?.id ?? null,
child3:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3?.id ?? null,
child4:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.id ?? null,
};
let fullname = "";
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: org?.child4 ?? "",
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: org?.child3 ?? "",
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: org?.child2 ?? "",
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
isDirector: true,
orgRootId: org?.root ?? "",
orgChild1Id: org?.child1 ?? "",
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
let pos = await this.posMasterRepository.findOne({
relations: ["current_holder"],
where: {
orgRevision: {
orgRevisionIsCurrent: true,
orgRevisionIsDraft: false,
},
orgRootId: org?.root ?? "",
orgChild1Id: IsNull(),
orgChild2Id: IsNull(),
orgChild3Id: IsNull(),
orgChild4Id: IsNull(),
},
});
if (pos) {
fullname =
pos.current_holder.prefix +
pos.current_holder.firstName +
" " +
pos.current_holder.lastName;
} else {
fullname = "";
}
}
}
}
}
const mapProfile = {
@ -1458,10 +1897,72 @@ export class OrganizationDotnetController extends Controller {
currentZipCode: profile.currentZipCode,
dutyTimeId: profile.dutyTimeId,
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
amountd: profile.amount,
root:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRoot?.orgRootName ?? null,
child1:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1?.orgChild1Name ?? null,
child2:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2?.orgChild2Name ?? null,
child3:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3?.orgChild3Name ?? null,
child4:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4?.orgChild4Name ?? null,
rootId:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgRootId ?? null,
child1Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild1Id ?? null,
child2Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild2Id ?? null,
child3Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild3Id ?? null,
child4Id:
profile?.current_holders?.find(
(x) =>
x.orgRevision?.orgRevisionIsDraft == false &&
x.orgRevision?.orgRevisionIsCurrent == true,
)?.orgChild4Id ?? null,
commander: fullname,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary,
profileInsignia: profile.profileInsignias,
profileSalary: profile.profileSalary.length > 0 ? profile.profileSalary[0] : null,
profileInsignia: profile.profileInsignias.length > 0 ? profile.profileInsignias[0] : null,
profileType: "OFFICER",
};