hrms-api-org/src/controllers/OrganizationUnauthorizeController.ts

1332 lines
52 KiB
TypeScript
Raw Normal View History

2025-02-06 17:16:09 +07:00
import { Controller, Get, Post, Route, Tags, Body, Path, Response, Patch, Query } from "tsoa";
import { OrgRevision } from "../entities/OrgRevision";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
2025-02-06 17:16:09 +07:00
import { Brackets, In, IsNull, Not } from "typeorm";
import { OrgRoot } from "../entities/OrgRoot";
import { PosMaster } from "../entities/PosMaster";
import { calculateRetireDate } from "../interfaces/utils";
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
2024-04-11 16:33:06 +07:00
import { Profile } from "../entities/Profile";
import { ProfileEmployee } from "../entities/ProfileEmployee";
2024-11-21 17:32:31 +07:00
import HttpStatus from "../interfaces/http-status";
2025-02-06 17:16:09 +07:00
import { ProfileAssessment } from "../entities/ProfileAssessment";
import { log } from "console";
import { format } from "path";
2025-02-07 18:04:12 +07:00
import { viewProfileEvaluation } from "../entities/view/viewProfileEvaluation";
@Route("api/v1/org/unauthorize")
@Tags("OrganizationUnauthorize")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
export class OrganizationUnauthorizeController extends Controller {
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private orgRootRepository = AppDataSource.getRepository(OrgRoot);
2024-11-14 16:25:46 +07:00
private profileRepo = AppDataSource.getRepository(Profile);
private profileEmpRepo = AppDataSource.getRepository(ProfileEmployee);
2025-02-06 17:16:09 +07:00
private profileAssessmentRepo = AppDataSource.getRepository(ProfileAssessment);
2025-02-07 18:04:12 +07:00
private viewProfileEvaluationRepo = AppDataSource.getRepository(viewProfileEvaluation);
2024-02-29 11:29:16 +07:00
/**
* API (unauthorize)
*
* @summary ORG_072 - #76 (unauthorize)
*
*/
2024-02-29 11:29:16 +07:00
@Post("salary/gen")
async salaryGen(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
year: number;
period: string;
2024-02-29 11:29:16 +07:00
},
) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const [findPosMaster, total] = await AppDataSource.getRepository(PosMaster)
.createQueryBuilder("posMaster")
.leftJoinAndSelect("posMaster.current_holder", "current_holder")
.leftJoinAndSelect("posMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("posMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("posMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("posMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("posMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("posMaster.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.leftJoinAndSelect("current_holder.profileSalary", "profileSalary")
2024-05-14 17:24:38 +07:00
.leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines")
2024-07-03 00:36:23 +07:00
.leftJoinAndSelect("current_holder.profileLeaves", "profileLeaves")
2024-06-17 17:39:26 +07:00
.leftJoinAndSelect("current_holder.profileAssessments", "profileAssessments")
2024-02-29 11:29:16 +07:00
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
.leftJoinAndSelect("current_holder.posType", "posType")
.where({
orgRevisionId: findRevision?.id,
current_holderId: Not(IsNull()),
})
.andWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "current_holder.prefix LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.firstName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posType.posTypeName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posLevel.posLevelName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
);
}),
)
.orderBy("current_holder.citizenId", "ASC")
2024-02-29 11:29:16 +07:00
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
}
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
if (item.orgChild1Id === null) {
orgShortName = item.orgRoot?.orgRootShortName;
} else if (item.orgChild2Id === null) {
orgShortName = item.orgChild1?.orgChild1ShortName;
} else if (item.orgChild3Id === null) {
orgShortName = item.orgChild2?.orgChild2ShortName;
} else if (item.orgChild4Id === null) {
orgShortName = item.orgChild3?.orgChild3ShortName;
} else {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
const posExecutive =
item.positions == null ||
item.positions?.find((position) => position.positionIsSelected == true) == null ||
item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: item.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
2024-12-26 23:05:55 +07:00
const amount = item.current_holder ? item.current_holder.amount : null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
let datePeriodEnd = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
if (body.period.toLocaleUpperCase() == "APR") {
datePeriodStart = new Date(`${body.year}-03-31T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-03-31T00:00:00.000Z`);
}
if (body.period.toLocaleUpperCase() == "OCT") {
datePeriodStart = new Date(`${body.year}-09-30T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-09-30T00:00:00.000Z`);
}
datePeriodStart = new Date(
new Date(datePeriodStart.setDate(datePeriodStart.getDate() + 1)).setMonth(
datePeriodStart.getMonth() - 6,
),
);
2024-04-11 16:33:06 +07:00
const specialPosition = item.positions.find(
(position) => position.positionIsSelected === true,
);
2024-04-02 15:57:56 +07:00
const isSpecial = specialPosition ? specialPosition.isSpecial : null;
2024-06-17 17:39:26 +07:00
const latestProfileAssessment = item.current_holder.profileAssessments
2024-07-03 00:36:23 +07:00
? item.current_holder.profileAssessments.sort((a: any, b: any) => b.date - a.date)[0]
2024-06-17 17:39:26 +07:00
: null;
2024-07-08 11:06:40 +07:00
const pointSum = latestProfileAssessment
? `(${this.textPointSummaryKpi(latestProfileAssessment.pointSum)})${latestProfileAssessment.pointSum}`
: null;
2024-02-29 11:29:16 +07:00
return {
2024-04-02 15:57:56 +07:00
id: item.id,
2024-04-25 00:36:54 +07:00
profileId: item.current_holder.id,
2024-02-29 11:29:16 +07:00
prefix: item.current_holder.prefix,
firstName: item.current_holder.firstName,
lastName: item.current_holder.lastName,
citizenId: item.current_holder.citizenId,
posMasterNoPrefix: item.posMasterNoPrefix,
posMasterNo: item.posMasterNo,
posMasterNoSuffix: item.posMasterNoSuffix,
orgShortName: orgShortName,
position: item.current_holder.position,
posType:
item.current_holder.posType == null ? null : item.current_holder.posType.posTypeName,
posLevel:
item.current_holder.posLevel == null ? null : item.current_holder.posLevel.posLevelName,
2024-02-29 11:29:16 +07:00
posExecutive: posExecutive,
amount: amount ? amount : null,
2024-02-29 11:29:16 +07:00
rootId: item.orgRootId,
root: item.orgRoot?.orgRootName ? item.orgRoot.orgRootName : null,
child1Id: item.orgChild1Id,
child1: item.orgChild1?.orgChild1Name ? item.orgChild1.orgChild1Name : null,
child2Id: item.orgChild2Id,
child2: item.orgChild2?.orgChild2Name ? item.orgChild2.orgChild2Name : null,
child3Id: item.orgChild3Id,
child3: item.orgChild3?.orgChild3Name ? item.orgChild3.orgChild3Name : null,
child4Id: item.orgChild4Id,
child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null,
2024-07-03 09:18:17 +07:00
result: pointSum,
2024-02-29 11:29:16 +07:00
duration: null,
isPunish:
2024-05-14 17:24:38 +07:00
item.current_holder.profileDisciplines.filter(
(x: any) =>
new Date(
`${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) >= datePeriodStart &&
new Date(
`${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) <= datePeriodEnd,
).length > 0
? true
: false,
isSuspension: item.current_holder.dateRetire == null ? false : true,
2024-07-03 00:36:23 +07:00
isAbsent: item.current_holder.profileDisciplines.length > 0 ? true : false,
isLeave: item.current_holder.profileLeaves.length > 0 ? true : false,
isRetired:
item.current_holder.birthDate == null ||
calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year
? false
: true,
2024-04-11 16:33:06 +07:00
isSpecial: isSpecial,
};
});
return new HttpSuccess({ data: formattedData, total: total });
}
/**
* API (unauthorize)
*
* @summary ORG_072 - #76 (unauthorize)
*
*/
@Post("salary/employee/gen")
async salaryEmployeeGen(
@Body()
body: {
page: number;
pageSize: number;
keyword?: string;
year: number;
period: string;
},
) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const [findPosMaster, total] = await AppDataSource.getRepository(EmployeePosMaster)
.createQueryBuilder("employeePosMaster")
.leftJoinAndSelect("employeePosMaster.current_holder", "current_holder")
.leftJoinAndSelect("employeePosMaster.orgRoot", "orgRoot")
.leftJoinAndSelect("employeePosMaster.orgChild1", "orgChild1")
.leftJoinAndSelect("employeePosMaster.orgChild2", "orgChild2")
.leftJoinAndSelect("employeePosMaster.orgChild3", "orgChild3")
.leftJoinAndSelect("employeePosMaster.orgChild4", "orgChild4")
.leftJoinAndSelect("employeePosMaster.positions", "positions")
.leftJoinAndSelect("current_holder.profileSalary", "profileSalary")
2024-05-14 17:24:38 +07:00
.leftJoinAndSelect("current_holder.profileDisciplines", "profileDisciplines")
2024-07-03 00:36:23 +07:00
.leftJoinAndSelect("current_holder.profileLeaves", "profileLeaves")
2024-06-17 17:39:26 +07:00
.leftJoinAndSelect("current_holder.profileAssessments", "profileAssessments")
.leftJoinAndSelect("current_holder.posLevel", "posLevel")
.leftJoinAndSelect("current_holder.posType", "posType")
.where({
orgRevisionId: findRevision?.id,
current_holderId: Not(IsNull()),
})
.andWhere(
new Brackets((qb) => {
qb.where(
body.keyword != null && body.keyword != ""
? "current_holder.prefix LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.firstName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.lastName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.position LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "current_holder.citizenId LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posType.posTypeName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
)
.orWhere(
body.keyword != null && body.keyword != ""
? "posLevel.posLevelName LIKE :keyword"
: "1=1",
{
keyword: `%${body.keyword}%`,
},
);
}),
)
.orderBy("current_holder.citizenId", "ASC")
.skip((body.page - 1) * body.pageSize)
.take(body.pageSize)
.getManyAndCount();
if (!findPosMaster) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. PosMaster");
}
const formattedData = findPosMaster.map((item) => {
let orgShortName = "";
if (item.orgChild1Id === null) {
orgShortName = item.orgRoot?.orgRootShortName;
} else if (item.orgChild2Id === null) {
orgShortName = item.orgChild1?.orgChild1ShortName;
} else if (item.orgChild3Id === null) {
orgShortName = item.orgChild2?.orgChild2ShortName;
} else if (item.orgChild4Id === null) {
orgShortName = item.orgChild3?.orgChild3ShortName;
} else {
orgShortName = item.orgChild4?.orgChild4ShortName;
}
// const amount =
// item.current_holder == null || item.current_holder.profileSalary.length == 0
// ? null
// : item.current_holder.profileSalary.sort((a: any, b: any) => b.date - a.date)[0].amount;
2024-12-26 23:05:55 +07:00
const amount = item.current_holder ? item.current_holder.amount : null;
let datePeriodStart = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
let datePeriodEnd = new Date(
`${new Date().getFullYear()}-${String(new Date().getMonth() + 1).padStart(2, "0")}-${String(new Date().getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
);
if (body.period.toLocaleUpperCase() == "APR") {
datePeriodStart = new Date(`${body.year}-03-31T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-03-31T00:00:00.000Z`);
}
if (body.period.toLocaleUpperCase() == "OCT") {
datePeriodStart = new Date(`${body.year}-09-30T00:00:00.000Z`);
datePeriodEnd = new Date(`${body.year}-09-30T00:00:00.000Z`);
}
datePeriodStart = new Date(
new Date(datePeriodStart.setDate(datePeriodStart.getDate() + 1)).setMonth(
datePeriodStart.getMonth() - 6,
),
);
2024-07-03 00:36:23 +07:00
const latestProfileAssessment = item.current_holder.profileAssessments
? item.current_holder.profileAssessments.sort((a: any, b: any) => b.date - a.date)[0]
: null;
2024-07-08 11:06:40 +07:00
const pointSum = latestProfileAssessment
? `(${this.textPointSummaryKpi(latestProfileAssessment.pointSum)})${latestProfileAssessment.pointSum}`
: null;
return {
2024-04-25 00:36:54 +07:00
profileId: item.current_holder.id,
salaryLevel: item.current_holder.salaryLevel,
group: item.current_holder.group,
prefix: item.current_holder.prefix,
firstName: item.current_holder.firstName,
lastName: item.current_holder.lastName,
citizenId: item.current_holder.citizenId,
posMasterNoPrefix: item.posMasterNoPrefix,
posMasterNo: item.posMasterNo,
posMasterNoSuffix: item.posMasterNoSuffix,
orgShortName: orgShortName,
position: item.current_holder.position,
2024-03-18 14:53:24 +07:00
posType:
item.current_holder.posType == null ? null : item.current_holder.posType.posTypeName,
2024-03-21 16:57:44 +07:00
posTypeShort:
item.current_holder.posType == null ? null : item.current_holder.posType.posTypeShortName,
2024-03-18 14:53:24 +07:00
posLevel:
item.current_holder.posLevel == null ? null : item.current_holder.posLevel.posLevelName,
amount: amount ? amount : null,
rootId: item.orgRootId,
root: item.orgRoot?.orgRootName ? item.orgRoot.orgRootName : null,
child1Id: item.orgChild1Id,
child1: item.orgChild1?.orgChild1Name ? item.orgChild1.orgChild1Name : null,
child2Id: item.orgChild2Id,
child2: item.orgChild2?.orgChild2Name ? item.orgChild2.orgChild2Name : null,
child3Id: item.orgChild3Id,
child3: item.orgChild3?.orgChild3Name ? item.orgChild3.orgChild3Name : null,
child4Id: item.orgChild4Id,
child4: item.orgChild4?.orgChild4Name ? item.orgChild4.orgChild4Name : null,
2024-07-03 00:36:23 +07:00
result: pointSum,
duration: null,
isPunish:
2024-05-14 17:24:38 +07:00
item.current_holder.profileDisciplines.filter(
(x: any) =>
new Date(
`${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) >= datePeriodStart &&
new Date(
`${new Date(x.date).getFullYear()}-${String(new Date(x.date).getMonth() + 1).padStart(2, "0")}-${String(new Date(x.date).getDate() + 1).padStart(2, "0")}T00:00:00.000Z`,
) <= datePeriodEnd,
).length > 0
? true
: false,
isSuspension: item.current_holder.dateRetire == null ? false : true,
2024-07-03 00:36:23 +07:00
isAbsent: item.current_holder.profileDisciplines.length > 0 ? true : false,
isLeave: item.current_holder.profileLeaves.length > 0 ? true : false,
isRetired:
item.current_holder.birthDate == null ||
calculateRetireDate(item.current_holder.birthDate).getFullYear() != body.year
? false
: true,
2024-02-29 11:29:16 +07:00
};
});
return new HttpSuccess({ data: formattedData, total: total });
}
/**
* API (unauthorize)
*
* @summary (unauthorize)
*
*/
@Get("active/root/id")
async _GetActiveRootId() {
try {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!orgRevisionActive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร่อยู่ตอนนี้");
}
const data = await this.orgRootRepository.find({
where: { orgRevisionId: orgRevisionActive.id },
});
2024-03-27 16:40:17 +07:00
return new HttpSuccess(
data.map((x) => ({
rootId: x.id,
root: x.orgRootName,
2025-02-04 17:34:43 +07:00
rootDnaId: x.ancestorDNA,
2024-03-27 16:40:17 +07:00
})),
);
} catch (error) {
return error;
}
}
/**
* API revision (unauthorize)
*
* @summary revision (unauthorize)
*
*/
@Get("revision/latest")
async _salaryGen() {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างล่าสุด");
}
return new HttpSuccess(findRevision.id);
}
2024-04-11 16:33:06 +07:00
/**
* API user profile officer
*
* @summary user profile officer
*
*/
@Get("officer/{id}")
async GetProfileById(@Path() id: string) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findProfile = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.positions", "positions")
2024-04-11 16:33:06 +07:00
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where({ id: id })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
const posExecutive =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions ==
null ||
findProfile.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions
.length == 0 ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true) == null ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const root =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
2024-04-11 16:33:06 +07:00
return new HttpSuccess({
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: findRevision.id,
profileId: findProfile.id,
2024-04-11 16:33:06 +07:00
type: "OFFICER",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posExecutive: posExecutive,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
/**
* API user profile employee
*
* @summary user profile employee
*
*/
@Get("employee/{id}")
async GetProfileEmployeeById(@Path() id: string) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
2024-04-11 16:33:06 +07:00
const findProfile = await AppDataSource.getRepository(ProfileEmployee)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.positions", "positions")
2024-04-11 16:33:06 +07:00
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where({ id: id })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
const root =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
2024-04-11 16:33:06 +07:00
return new HttpSuccess({
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: findRevision.id,
profileId: findProfile.id,
2024-04-11 16:33:06 +07:00
type: "OFFICER",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
/**
* API user profile officer
*
* @summary user profile officer
*
*/
@Get("officer/citizen/{id}")
async GetProfileByCitizenId(@Path() id: string) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findProfile = await AppDataSource.getRepository(Profile)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
2024-04-18 11:59:43 +07:00
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
.leftJoinAndSelect("positions.posExecutive", "posExecutive")
2024-12-16 17:39:27 +07:00
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id })
.andWhere({ citizenId: id })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
const posExecutive =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.positions ==
null ||
findProfile.current_holders?.find((x) => x.orgRevisionId == findRevision.id)?.positions
.length == 0 ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true) == null ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive ==
null ||
findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
?.posExecutiveName == null
? null
: findProfile.current_holders
.find((x) => x.orgRevisionId == findRevision.id)
?.positions?.find((position) => position.positionIsSelected == true)?.posExecutive
.posExecutiveName;
const root =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
2024-04-25 00:36:54 +07:00
2024-04-18 11:59:43 +07:00
const child1 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
const child2 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
const child3 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
2024-04-25 00:36:54 +07:00
2024-04-18 11:59:43 +07:00
const child4 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
2024-04-25 00:36:54 +07:00
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
let _root = root == null ? "" : `${root.orgRootName}`;
2024-04-18 11:59:43 +07:00
return new HttpSuccess({
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: findRevision.id,
profileId: findProfile.id,
org: `${_child4}${_child3}${_child2}${_child1}${_root}`,
type: "OFFICER",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posExecutive: posExecutive,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
/**
* API user profile employee
*
* @summary user profile employee
*
*/
@Get("employee/citizen/{id}")
async GetProfileEmployeeByCitizenId(@Path() id: string) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findProfile = await AppDataSource.getRepository(ProfileEmployee)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
2024-04-18 11:59:43 +07:00
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
2024-04-18 11:59:43 +07:00
// .leftJoinAndSelect("positions.posExecutive", "posExecutive")
.where({ citizenId: id })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
const root =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
const child1 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
const child2 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
const child3 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
const child4 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
let _root = root == null ? "" : `${root.orgRootName}`;
return new HttpSuccess({
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: findRevision.id,
profileId: findProfile.id,
org: `${_child4}${_child3}${_child2}${_child1}${_root}`,
type: "EMPLOYEE",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
/**
* API user profile employee
*
* @summary user profile employee
*
*/
@Get("employee-prem/citizen/{id}")
async GetProfileEmployeePremByCitizenId(@Path() id: string) {
const findRevision = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true },
});
if (!findRevision) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found. OrgRevision");
}
const findProfile = await AppDataSource.getRepository(ProfileEmployee)
.createQueryBuilder("profile")
.leftJoinAndSelect("profile.current_holders", "current_holders")
.leftJoinAndSelect("current_holders.orgRoot", "orgRoot")
.leftJoinAndSelect("current_holders.orgChild1", "orgChild1")
.leftJoinAndSelect("current_holders.orgChild2", "orgChild2")
.leftJoinAndSelect("current_holders.orgChild3", "orgChild3")
.leftJoinAndSelect("current_holders.orgChild4", "orgChild4")
.leftJoinAndSelect("current_holders.positions", "positions")
2024-12-16 17:39:27 +07:00
.where("current_holders.orgRevisionId = :orgRevisionId", { orgRevisionId: findRevision.id })
// .leftJoinAndSelect("positions.posExecutive", "posExecutive")
2024-12-16 17:39:27 +07:00
.andWhere({ citizenId: id, employeeClass: "PERM" })
.getOne();
if (!findProfile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found Profile");
}
const root =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgRoot;
2024-04-18 11:59:43 +07:00
const child1 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild1;
const child2 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild2;
const child3 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild3;
2024-04-25 00:36:54 +07:00
2024-04-18 11:59:43 +07:00
const child4 =
findProfile.current_holders == null ||
findProfile.current_holders.length == 0 ||
findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id) == null
? null
: findProfile.current_holders.find((x) => x.orgRevisionId == findRevision.id)?.orgChild4;
2024-04-25 00:36:54 +07:00
let _child1 = child1 == null ? "" : `${child1.orgChild1Name}/`;
let _child2 = child2 == null ? "" : `${child2.orgChild2Name}/`;
let _child3 = child3 == null ? "" : `${child3.orgChild3Name}/`;
let _child4 = child4 == null ? "" : `${child4.orgChild4Name}/`;
let _root = root == null ? "" : `${root.orgRootName}`;
2024-04-18 11:59:43 +07:00
return new HttpSuccess({
rootId: root == null ? null : root.id,
root: root == null ? null : root.orgRootName,
orgRootShortName: root == null ? null : root.orgRootShortName,
orgRevisionId: findRevision.id,
profileId: findProfile.id,
org: `${_child4}${_child3}${_child2}${_child1}${_root}`,
type: "EMPLOYEE",
rank: findProfile.rank,
prefix: findProfile.prefix,
firstName: findProfile.firstName,
lastName: findProfile.lastName,
citizenId: findProfile.citizenId,
position: findProfile.position,
posLevelId: findProfile.posLevelId,
posTypeId: findProfile.posTypeId,
});
}
2024-07-08 11:06:40 +07:00
textPointSummaryKpi(val: number | undefined) {
if (val == undefined || val == null) val = -1;
if (val >= 0 && val <= 60) return "ต้องปรับปรุง";
if (val >= 60 && val <= 69) return "พอใช้";
if (val >= 70 && val <= 79) return "ดี";
if (val >= 80 && val <= 89) return "ดีมาก";
if (val >= 90 && val <= 100) return "ดีเด่น";
2024-12-26 23:05:55 +07:00
if (val > 101) return "ดีเด่น";
2024-07-08 11:06:40 +07:00
else return "-";
}
2024-11-14 14:58:31 +07:00
/**
* API
*
* @summary
*
*/
@Get("active/root/all")
async GetActiveRootAll() {
const orgRevisionActive = await this.orgRevisionRepository.findOne({
where: { orgRevisionIsCurrent: true, orgRevisionIsDraft: false },
});
if (!orgRevisionActive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบโครงสร้างที่เผยแพร่อยู่ตอนนี้");
}
const data = await this.orgRootRepository.find({
where: { orgRevisionId: orgRevisionActive.id },
});
return new HttpSuccess(data);
}
2024-11-14 16:25:46 +07:00
/**
* 3. API Get Profile keycloak id
*
* @summary 3. API Get Profile keycloak id
*
* @param {string} keycloakId Id keycloak
*/
@Get("root/officer/{rootId}")
async GetProfileByRootIdAsync(@Path() rootId: string) {
const profiles = await this.profileRepo.find({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
where: { current_holders: { orgRootId: rootId } },
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const mapProfile = profiles.map((profile) => ({
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,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary,
profileInsignia: profile.profileInsignias,
}));
return new HttpSuccess(mapProfile);
}
/**
* 3. API Get Profile keycloak id
*
* @summary 3. API Get Profile keycloak id
*
* @param {string} keycloakId Id keycloak
*/
@Get("root/employee/{rootId}")
async GetProfileByRootIdEmpAsync(@Path() rootId: string) {
const profiles = await this.profileEmpRepo.find({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileInsignias: true,
},
where: { current_holders: { orgRootId: rootId } },
order: {
profileSalary: {
date: "DESC",
},
profileInsignias: {
receiveDate: "DESC",
},
},
});
// if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const mapProfile = profiles.map((profile) => ({
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,
posLevel: profile.posLevel ? profile.posLevel : null,
posType: profile.posType ? profile.posType : null,
profileSalary: profile.profileSalary,
profileInsignia: profile.profileInsignias,
}));
return new HttpSuccess(mapProfile);
}
2024-11-21 17:32:31 +07:00
/**
* API Email
*
* @summary Email
*
*/
@Post("verify-email")
async genLinkVerifyEmail(@Body() body: { token: string }) {
const jwt = require("jsonwebtoken");
const secretKey = process.env.AUTH_ACCOUNT_SECRET || "defaultSecretKey";
const decodedToken = jwt.verify(body.token, secretKey);
// console.log("[email]",decodedToken);
// console.log("[1]",decodedToken.email_id);
const profile = await this.profileRepo.findOne({
where: {
id: decodedToken.profileId,
email: decodedToken.email_id,
},
});
if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์");
}
Object.assign(profile, body);
profile.statusEmail = "VERIFIED";
await this.profileRepo.save(profile);
return new HttpSuccess("Email verified successfully.");
2024-11-21 17:32:31 +07:00
}
2025-01-29 15:41:14 +07:00
2025-02-06 17:16:09 +07:00
/**
* API 5
*
* @summary 5
*
*/
2025-02-10 10:48:15 +07:00
@Get("calculateEvaluation")
async calculateEvaluation(
// @Path() node: number,
// @Path() nodeId: string,
2025-02-06 17:16:09 +07:00
) {
2025-02-10 10:48:15 +07:00
// let condition :any = {};
// switch (node) {
// case 0:
// condition = {orgRootId: nodeId}
// break;
// case 1:
// condition = {orgChild1Id: nodeId}
// break;
// case 2:
// condition = {orgChild2Id: nodeId}
// break;
// case 3:
// condition = {orgChild3Id: nodeId}
// break;
// case 4:
// condition = {orgChild4Id: nodeId}
// break;
// default:
// throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// }
2025-02-06 17:16:09 +07:00
2025-02-07 18:04:12 +07:00
const lists = await this.viewProfileEvaluationRepo.find({
// where:{
2025-02-10 10:48:15 +07:00
// ...condition
2025-02-07 18:04:12 +07:00
// }
})
2025-02-10 10:48:15 +07:00
const groupData: any = {};
2025-02-07 18:04:12 +07:00
const year = new Date().getFullYear();
const years = [year, year - 1, year - 2, year - 3, year - 4];
2025-02-06 17:16:09 +07:00
2025-02-07 18:04:12 +07:00
lists.forEach((item: any) => {
2025-02-10 10:48:15 +07:00
if (!groupData[item.profileId]) {
groupData[item.profileId] = {
2025-02-07 18:04:12 +07:00
profileId: item.profileId,
yearAPR1: "-", periodAPR1: "-", resultAPR1: "-",
yearOCT1: "-", periodOCT1: "-", resultOCT1: "-",
yearAPR2: "-", periodAPR2: "-", resultAPR2: "-",
yearOCT2: "-", periodOCT2: "-", resultOCT2: "-",
yearAPR3: "-", periodAPR3: "-", resultAPR3: "-",
yearOCT3: "-", periodOCT3: "-", resultOCT3: "-",
yearAPR4: "-", periodAPR4: "-", resultAPR4: "-",
yearOCT4: "-", periodOCT4: "-", resultOCT4: "-",
yearAPR5: "-", periodAPR5: "-", resultAPR5: "-",
yearOCT5: "-", periodOCT5: "-", resultOCT5: "-"
};
}
2025-02-06 17:16:09 +07:00
2025-02-07 18:04:12 +07:00
const yearIndex = years.indexOf(parseInt(item.year));
if (yearIndex !== -1) {
const yearSuffix = yearIndex + 1;
const yearKey = `year${item.period}${yearSuffix}`;
const periodKey = `period${item.period}${yearSuffix}`;
const resultKey = `result${item.period}${yearSuffix}`;
2025-02-06 17:16:09 +07:00
2025-02-10 10:48:15 +07:00
groupData[item.profileId][yearKey] = item.year;
groupData[item.profileId][periodKey] = item.period;
groupData[item.profileId][resultKey] = item.result;
2025-02-07 18:04:12 +07:00
}
});
2025-02-06 17:16:09 +07:00
2025-02-10 10:48:15 +07:00
const formattedResults = Object.values(groupData).map((item: any) => ({
profileId: item.profileId,
yearAPR1: item.yearAPR1,
periodAPR1: item.periodAPR1,
resultAPR1: item.resultAPR1,
yearOCT1: item.yearOCT1,
periodOCT1: item.periodOCT1,
resultOCT1: item.resultOCT1,
yearAPR2: item.yearAPR2,
periodAPR2: item.periodAPR2,
resultAPR2: item.resultAPR2,
yearOCT2: item.yearOCT2,
periodOCT2: item.periodOCT2,
resultOCT2: item.resultOCT2,
yearAPR3: item.yearAPR3,
periodAPR3: item.periodAPR3,
resultAPR3: item.resultAPR3,
yearOCT3: item.yearOCT3,
periodOCT3: item.periodOCT3,
resultOCT3: item.resultOCT3,
yearAPR4: item.yearAPR4,
periodAPR4: item.periodAPR4,
resultAPR4: item.resultAPR4,
yearOCT4: item.yearOCT4,
periodOCT4: item.periodOCT4,
resultOCT4: item.resultOCT4,
}));
2025-02-07 18:04:12 +07:00
return new HttpSuccess(formattedResults);
2025-02-06 17:16:09 +07:00
}
// @Patch("retirement")
// public async updateStatusRetirement(
// @Body()
// body: {
// data: {
// profileId: string;
// }[];
// },
// ) {
// let profiles: Profile[] = [];
// let _null: any = null;
// await Promise.all(
// body.data.map(async (item) => {
// const _profile = await this.profileRepo.findOneBy({ id: item.profileId });
// if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// _profile.isRetirement = true;
// _profile.isLeave = true;
// _profile.leaveType = "RETIRE";
// _profile.leaveDate = new Date();
// _profile.dateLeave = new Date();
// _profile.lastUpdatedAt = new Date();
// profiles.push(_profile);
// })
// );
// await this.profileRepo.save(profiles);
// return new HttpSuccess();
// }
2025-01-29 15:41:14 +07:00
// @Patch("retirement-employee")
// public async updateStatusRetirementEmp(
// @Body()
// body: {
// data: {
// profileId: string;
// }[];
// },
// ) {
// let profiles: ProfileEmployee[] = [];
// let _null: any = null;
// await Promise.all(
// body.data.map(async (item) => {
// const _profile = await this.profileEmpRepo.findOneBy({ id: item.profileId });
// if (!_profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
// _profile.isRetirement = true;
// _profile.isLeave = true;
// _profile.leaveType = "RETIRE";
// _profile.leaveDate = new Date();
// _profile.dateLeave = new Date();
// _profile.lastUpdatedAt = new Date();
// profiles.push(_profile);
// })
// );
// await this.profileEmpRepo.save(profiles);
// return new HttpSuccess();
// }
}