This commit is contained in:
parent
7739af7d44
commit
7b84f8af7b
1 changed files with 587 additions and 61 deletions
|
|
@ -21,6 +21,7 @@ import { viewProfileEmployeeEvaluation } from "../entities/view/viewProfileEmplo
|
||||||
import Extension from "../interfaces/extension";
|
import Extension from "../interfaces/extension";
|
||||||
import { resetPassword } from "../keycloak";
|
import { resetPassword } from "../keycloak";
|
||||||
import { viewEmployeePosMaster } from "../entities/view/viewEmployeePosMaster";
|
import { viewEmployeePosMaster } from "../entities/view/viewEmployeePosMaster";
|
||||||
|
import { EmployeePosDict } from "../entities/EmployeePosDict";
|
||||||
@Route("api/v1/org/unauthorize")
|
@Route("api/v1/org/unauthorize")
|
||||||
@Tags("OrganizationUnauthorize")
|
@Tags("OrganizationUnauthorize")
|
||||||
@Response(
|
@Response(
|
||||||
|
|
@ -37,6 +38,7 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository(
|
private viewProfileEmployeeEvaluationRepo = AppDataSource.getRepository(
|
||||||
viewProfileEmployeeEvaluation,
|
viewProfileEmployeeEvaluation,
|
||||||
);
|
);
|
||||||
|
private employeePosDictRepository = AppDataSource.getRepository(EmployeePosDict);
|
||||||
|
|
||||||
@Post("user/reset-password")
|
@Post("user/reset-password")
|
||||||
async forgetPassword(
|
async forgetPassword(
|
||||||
|
|
@ -1505,22 +1507,25 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
return new HttpSuccess(data);
|
return new HttpSuccess(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 3. API Get Profile จาก keycloak id
|
|
||||||
*
|
|
||||||
* @summary 3. API Get Profile จาก keycloak id
|
|
||||||
*
|
|
||||||
* @param {string} keycloakId Id keycloak
|
|
||||||
*/
|
|
||||||
@Get("root/officer/{rootId}")
|
@Get("root/officer/{rootId}")
|
||||||
async GetProfileByRootIdAsync(@Path() rootId: string) {
|
async GetProfileByRootIdAsync(@Path() rootId: string) {
|
||||||
const profiles = await this.profileRepo.find({
|
const profiles = await this.profileRepo.find({
|
||||||
relations: {
|
relations: [
|
||||||
posLevel: true,
|
"posLevel",
|
||||||
posType: true,
|
"posType",
|
||||||
profileSalary: true,
|
"profileSalary",
|
||||||
profileInsignias: true,
|
"profileInsignias",
|
||||||
},
|
"profileInsignias.insignia",
|
||||||
|
"profileDisciplines",
|
||||||
|
"profileAssessments",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRevision",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
],
|
||||||
where: { current_holders: { orgRootId: rootId } },
|
where: { current_holders: { orgRootId: rootId } },
|
||||||
order: {
|
order: {
|
||||||
profileSalary: {
|
profileSalary: {
|
||||||
|
|
@ -1531,55 +1536,267 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
|
||||||
|
|
||||||
const mapProfile = profiles.map((profile) => ({
|
const currentYear = new Date().getFullYear();
|
||||||
id: profile.id,
|
const years = [currentYear, currentYear - 1, currentYear - 2, currentYear - 3, currentYear - 4];
|
||||||
avatar: profile.avatar,
|
|
||||||
avatarName: profile.avatarName,
|
// APR Averages
|
||||||
rank: profile.rank,
|
const aprAverages: { [year: number]: number | null } = {};
|
||||||
prefix: profile.prefix,
|
const aprSums: { [year: number]: number } = {};
|
||||||
firstName: profile.firstName,
|
const aprCounts: { [year: number]: number } = {};
|
||||||
lastName: profile.lastName,
|
|
||||||
citizenId: profile.citizenId,
|
// OCT Averages
|
||||||
position: profile.position,
|
const octAverages: { [year: number]: number | null } = {};
|
||||||
posLevelId: profile.posLevelId,
|
const octSums: { [year: number]: number } = {};
|
||||||
email: profile.email,
|
const octCounts: { [year: number]: number } = {};
|
||||||
phone: profile.phone,
|
|
||||||
keycloak: profile.keycloak,
|
years.forEach((year) => {
|
||||||
isProbation: profile.isProbation,
|
aprAverages[year] = null;
|
||||||
isLeave: profile.isLeave,
|
aprSums[year] = 0;
|
||||||
leaveReason: profile.leaveReason,
|
aprCounts[year] = 0;
|
||||||
dateRetire: profile.dateRetire,
|
|
||||||
dateAppoint: profile.dateAppoint,
|
octAverages[year] = null;
|
||||||
dateRetireLaw: profile.dateRetireLaw,
|
octSums[year] = 0;
|
||||||
dateStart: profile.dateStart,
|
octCounts[year] = 0;
|
||||||
govAgeAbsent: profile.govAgeAbsent,
|
});
|
||||||
govAgePlus: profile.govAgePlus,
|
|
||||||
birthDate: profile.birthDate,
|
profiles.forEach((profile) => {
|
||||||
reasonSameDate: profile.reasonSameDate,
|
const assessments = profile.profileAssessments || [];
|
||||||
telephoneNumber: profile.phone,
|
|
||||||
nationality: profile.nationality,
|
assessments.forEach((assessment) => {
|
||||||
gender: profile.gender,
|
const year = Number(assessment.year);
|
||||||
relationship: profile.relationship,
|
|
||||||
religion: profile.religion,
|
if (years.includes(year)) {
|
||||||
bloodGroup: profile.bloodGroup,
|
if (assessment.period === "APR") {
|
||||||
registrationAddress: profile.registrationAddress,
|
aprSums[year] += assessment.pointSum;
|
||||||
registrationProvinceId: profile.registrationProvinceId,
|
aprCounts[year] += 1;
|
||||||
registrationDistrictId: profile.registrationDistrictId,
|
}
|
||||||
registrationSubDistrictId: profile.registrationSubDistrictId,
|
|
||||||
registrationZipCode: profile.registrationZipCode,
|
if (assessment.period === "OCT") {
|
||||||
currentAddress: profile.currentAddress,
|
octSums[year] += assessment.pointSum;
|
||||||
currentProvinceId: profile.currentProvinceId,
|
octCounts[year] += 1;
|
||||||
currentSubDistrictId: profile.currentSubDistrictId,
|
}
|
||||||
currentZipCode: profile.currentZipCode,
|
}
|
||||||
dutyTimeId: profile.dutyTimeId,
|
});
|
||||||
dutyTimeEffectiveDate: profile.dutyTimeEffectiveDate,
|
});
|
||||||
posLevel: profile.posLevel ? profile.posLevel : null,
|
|
||||||
posType: profile.posType ? profile.posType : null,
|
years.forEach((year) => {
|
||||||
profileSalary: profile.profileSalary,
|
aprAverages[year] = aprCounts[year] > 0 ? aprSums[year] / aprCounts[year] : null;
|
||||||
profileInsignia: profile.profileInsignias,
|
octAverages[year] = octCounts[year] > 0 ? octSums[year] / octCounts[year] : null;
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
const findRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapProfile = profiles.map((profile) => {
|
||||||
|
const shortName =
|
||||||
|
profile.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||||
|
null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return {
|
||||||
|
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,
|
||||||
|
posTypeId: profile.posTypeId,
|
||||||
|
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 ?? new Date(),
|
||||||
|
reasonSameDate: profile.reasonSameDate,
|
||||||
|
telephoneNumber: profile.phone,
|
||||||
|
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,
|
||||||
|
posLevel: profile.posLevel?.posLevelName ?? "",
|
||||||
|
posType: profile.posType?.posTypeName ?? "",
|
||||||
|
profileSalary: profile.profileSalary,
|
||||||
|
profileInsignia: profile.profileInsignias.map((x) => {
|
||||||
|
return { ...x, insignia: x.insignia.name };
|
||||||
|
}),
|
||||||
|
amount: profile.amount,
|
||||||
|
positionSalaryAmount: profile.positionSalaryAmount,
|
||||||
|
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||||
|
profileType: "OFFICER",
|
||||||
|
root:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgRoot?.orgRootName ?? null,
|
||||||
|
rootId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgRootId ?? null,
|
||||||
|
rootDnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgRoot?.ancestorDNA ?? null,
|
||||||
|
child1:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild1?.orgChild1Name ?? null,
|
||||||
|
child1Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild1Id ?? null,
|
||||||
|
child1DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild1?.ancestorDNA ?? null,
|
||||||
|
child2:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild2?.orgChild2Name ?? null,
|
||||||
|
child2Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild2Id ?? null,
|
||||||
|
child2DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild2?.ancestorDNA ?? null,
|
||||||
|
child3:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild3?.orgChild3Name ?? null,
|
||||||
|
child3Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild3Id ?? null,
|
||||||
|
child3DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild3?.ancestorDNA ?? null,
|
||||||
|
child4:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild4?.orgChild4Name ?? null,
|
||||||
|
child4Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild4Id ?? null,
|
||||||
|
child4DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild4?.ancestorDNA ?? null,
|
||||||
|
posNo: shortName ?? "",
|
||||||
|
markDiscipline: profile.profileDisciplines.length > 0 ? true : false,
|
||||||
|
markLeave: false,
|
||||||
|
markRate: profile.profileAssessments.length > 0 ? true : false,
|
||||||
|
markInsignia: profile.profileInsignias.length > 0 ? true : false,
|
||||||
|
apr1: aprAverages[currentYear]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear] as number)
|
||||||
|
: null,
|
||||||
|
apr2: aprAverages[currentYear - 1]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 1] as number)
|
||||||
|
: null,
|
||||||
|
apr3: aprAverages[currentYear - 2]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 2] as number)
|
||||||
|
: null,
|
||||||
|
apr4: aprAverages[currentYear - 3]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 3] as number)
|
||||||
|
: null,
|
||||||
|
apr5: aprAverages[currentYear - 4]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 4] as number)
|
||||||
|
: null,
|
||||||
|
oct1: octAverages[currentYear]
|
||||||
|
? Extension.textPoint(octAverages[currentYear] as number)
|
||||||
|
: null,
|
||||||
|
oct2: octAverages[currentYear - 1]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 1] as number)
|
||||||
|
: null,
|
||||||
|
oct3: octAverages[currentYear - 2]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 2] as number)
|
||||||
|
: null,
|
||||||
|
oct4: octAverages[currentYear - 3]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 3] as number)
|
||||||
|
: null,
|
||||||
|
oct5: octAverages[currentYear - 4]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 4] as number)
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
return new HttpSuccess(mapProfile);
|
return new HttpSuccess(mapProfile);
|
||||||
}
|
}
|
||||||
|
|
@ -1663,6 +1880,315 @@ export class OrganizationUnauthorizeController extends Controller {
|
||||||
return new HttpSuccess(mapProfile);
|
return new HttpSuccess(mapProfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Post("find/employee/position")
|
||||||
|
async GetProfileByPositionEmpAsync(
|
||||||
|
@Body()
|
||||||
|
body: {
|
||||||
|
empPosId: string[];
|
||||||
|
rootId: string;
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
const findRevision = await this.orgRevisionRepository.findOne({
|
||||||
|
where: { orgRevisionIsCurrent: true },
|
||||||
|
});
|
||||||
|
const employeePosDict = await this.employeePosDictRepository.find({
|
||||||
|
where: { id: In(body.empPosId) },
|
||||||
|
});
|
||||||
|
|
||||||
|
const profiles = await this.profileEmpRepo.find({
|
||||||
|
relations: [
|
||||||
|
"posLevel",
|
||||||
|
"posType",
|
||||||
|
"profileSalary",
|
||||||
|
"profileInsignias",
|
||||||
|
"profileInsignias.insignia",
|
||||||
|
"profileDisciplines",
|
||||||
|
"profileAssessments",
|
||||||
|
"current_holders",
|
||||||
|
"current_holders.orgRevision",
|
||||||
|
"current_holders.orgRoot",
|
||||||
|
"current_holders.orgChild1",
|
||||||
|
"current_holders.orgChild2",
|
||||||
|
"current_holders.orgChild3",
|
||||||
|
"current_holders.orgChild4",
|
||||||
|
],
|
||||||
|
where: employeePosDict.map((entry) => ({
|
||||||
|
posLevelId: entry.posLevelId,
|
||||||
|
posTypeId: entry.posTypeId,
|
||||||
|
position: entry.posDictName,
|
||||||
|
current_holders: { orgRootId: body.rootId },
|
||||||
|
})),
|
||||||
|
order: {
|
||||||
|
profileSalary: {
|
||||||
|
commandDateAffect: "DESC",
|
||||||
|
},
|
||||||
|
profileInsignias: {
|
||||||
|
receiveDate: "DESC",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const currentYear = new Date().getFullYear();
|
||||||
|
const years = [currentYear, currentYear - 1, currentYear - 2, currentYear - 3, currentYear - 4];
|
||||||
|
|
||||||
|
// APR Averages
|
||||||
|
const aprAverages: { [year: number]: number | null } = {};
|
||||||
|
const aprSums: { [year: number]: number } = {};
|
||||||
|
const aprCounts: { [year: number]: number } = {};
|
||||||
|
|
||||||
|
// OCT Averages
|
||||||
|
const octAverages: { [year: number]: number | null } = {};
|
||||||
|
const octSums: { [year: number]: number } = {};
|
||||||
|
const octCounts: { [year: number]: number } = {};
|
||||||
|
|
||||||
|
years.forEach((year) => {
|
||||||
|
aprAverages[year] = null;
|
||||||
|
aprSums[year] = 0;
|
||||||
|
aprCounts[year] = 0;
|
||||||
|
|
||||||
|
octAverages[year] = null;
|
||||||
|
octSums[year] = 0;
|
||||||
|
octCounts[year] = 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
profiles.forEach((profile) => {
|
||||||
|
const assessments = profile.profileAssessments || [];
|
||||||
|
|
||||||
|
assessments.forEach((assessment) => {
|
||||||
|
const year = Number(assessment.year);
|
||||||
|
|
||||||
|
if (years.includes(year)) {
|
||||||
|
if (assessment.period === "APR") {
|
||||||
|
aprSums[year] += assessment.pointSum;
|
||||||
|
aprCounts[year] += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (assessment.period === "OCT") {
|
||||||
|
octSums[year] += assessment.pointSum;
|
||||||
|
octCounts[year] += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
years.forEach((year) => {
|
||||||
|
aprAverages[year] = aprCounts[year] > 0 ? aprSums[year] / aprCounts[year] : null;
|
||||||
|
octAverages[year] = octCounts[year] > 0 ? octSums[year] / octCounts[year] : null;
|
||||||
|
});
|
||||||
|
|
||||||
|
const mapProfile = profiles.map((profile) => {
|
||||||
|
const shortName =
|
||||||
|
profile.current_holders.length == 0
|
||||||
|
? null
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4 !=
|
||||||
|
null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild4.orgChild4ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild3 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild3.orgChild3ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) != null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild2 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild2.orgChild2ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgChild1 != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgChild1.orgChild1ShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id) !=
|
||||||
|
null &&
|
||||||
|
profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)
|
||||||
|
?.orgRoot != null
|
||||||
|
? `${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot.orgRootShortName} ${profile.current_holders.find((x) => x.orgRevisionId == findRevision?.id)?.posMasterNo}`
|
||||||
|
: null;
|
||||||
|
return {
|
||||||
|
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 ?? new Date(),
|
||||||
|
reasonSameDate: profile.reasonSameDate,
|
||||||
|
telephoneNumber: profile.phone,
|
||||||
|
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,
|
||||||
|
posLevel:
|
||||||
|
(profile.posType == null || profile.posType?.posTypeShortName == null
|
||||||
|
? ""
|
||||||
|
: profile.posType?.posTypeShortName + " ") + (profile.posLevel?.posLevelName ?? ""),
|
||||||
|
posType: profile.posType?.posTypeName ?? "",
|
||||||
|
profileSalary: profile.profileSalary.map((x) => {
|
||||||
|
return { ...x, date: x.commandDateAffect ?? new Date() };
|
||||||
|
}),
|
||||||
|
profileInsignia: profile.profileInsignias.map((x) => {
|
||||||
|
return { ...x, insignia: x.insignia.name };
|
||||||
|
}),
|
||||||
|
amount: profile.amount,
|
||||||
|
positionSalaryAmount: profile.positionSalaryAmount,
|
||||||
|
mouthSalaryAmount: profile.mouthSalaryAmount,
|
||||||
|
profileType: "EMPLOYEE",
|
||||||
|
root:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgRoot?.orgRootName ?? null,
|
||||||
|
rootId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgRootId ?? null,
|
||||||
|
rootDnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgRoot?.ancestorDNA ?? null,
|
||||||
|
child1:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild1?.orgChild1Name ?? null,
|
||||||
|
child1Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild1Id ?? null,
|
||||||
|
child1DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild1?.ancestorDNA ?? null,
|
||||||
|
child2:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild2?.orgChild2Name ?? null,
|
||||||
|
child2Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild2Id ?? null,
|
||||||
|
child2DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild2?.ancestorDNA ?? null,
|
||||||
|
child3:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild3?.orgChild3Name ?? null,
|
||||||
|
child3Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild3Id ?? null,
|
||||||
|
child3DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild3?.ancestorDNA ?? null,
|
||||||
|
child4:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild4?.orgChild4Name ?? null,
|
||||||
|
child4Id:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild4Id ?? null,
|
||||||
|
child4DnaId:
|
||||||
|
profile?.current_holders?.find(
|
||||||
|
(x) =>
|
||||||
|
x.orgRevision?.orgRevisionIsDraft == false &&
|
||||||
|
x.orgRevision?.orgRevisionIsCurrent == true,
|
||||||
|
)?.orgChild4?.ancestorDNA ?? null,
|
||||||
|
posNo: shortName ?? "",
|
||||||
|
markDiscipline: profile.profileDisciplines.length > 0 ? true : false,
|
||||||
|
markLeave: false,
|
||||||
|
markRate: profile.profileAssessments.length > 0 ? true : false,
|
||||||
|
markInsignia: profile.profileInsignias.length > 0 ? true : false,
|
||||||
|
apr1: aprAverages[currentYear]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear] as number)
|
||||||
|
: null,
|
||||||
|
apr2: aprAverages[currentYear - 1]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 1] as number)
|
||||||
|
: null,
|
||||||
|
apr3: aprAverages[currentYear - 2]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 2] as number)
|
||||||
|
: null,
|
||||||
|
apr4: aprAverages[currentYear - 3]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 3] as number)
|
||||||
|
: null,
|
||||||
|
apr5: aprAverages[currentYear - 4]
|
||||||
|
? Extension.textPoint(aprAverages[currentYear - 4] as number)
|
||||||
|
: null,
|
||||||
|
oct1: octAverages[currentYear]
|
||||||
|
? Extension.textPoint(octAverages[currentYear] as number)
|
||||||
|
: null,
|
||||||
|
oct2: octAverages[currentYear - 1]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 1] as number)
|
||||||
|
: null,
|
||||||
|
oct3: octAverages[currentYear - 2]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 2] as number)
|
||||||
|
: null,
|
||||||
|
oct4: octAverages[currentYear - 3]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 3] as number)
|
||||||
|
: null,
|
||||||
|
oct5: octAverages[currentYear - 4]
|
||||||
|
? Extension.textPoint(octAverages[currentYear - 4] as number)
|
||||||
|
: null,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return new HttpSuccess(mapProfile);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ยืนยัน Email
|
* API ยืนยัน Email
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue