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

283 lines
8.5 KiB
TypeScript
Raw Normal View History

2024-10-08 11:47:05 +07:00
import { Controller, Example, Get, Path, Response, Route, SuccessResponse, Tags } from "tsoa";
2024-10-07 14:53:27 +07:00
2024-10-08 11:47:05 +07:00
import { DateTime } from "@elastic/elasticsearch/lib/api/types";
import { Double } from "typeorm";
2024-10-07 14:53:27 +07:00
import { AppDataSource } from "../database/data-source";
2024-10-17 11:34:03 +07:00
import { OrgRevision } from "../entities/OrgRevision";
2024-10-07 14:53:27 +07:00
import { Profile } from "../entities/Profile";
import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status";
2024-10-08 11:47:05 +07:00
interface DPISResponse {
2024-10-17 10:47:10 +07:00
/**
*
*/
2024-10-08 11:47:05 +07:00
status: number;
2024-10-17 11:34:03 +07:00
/**
*
*/
2024-10-08 11:47:05 +07:00
message: string;
2024-10-17 11:34:03 +07:00
/**
*
*/
2024-10-08 11:47:05 +07:00
result?: DPISResult;
}
interface DPISResult {
citizenId: string;
prefix: string;
firstName: string;
lastName: string;
gender: string;
physicalStatus: string;
QualityWorkforce: boolean;
birthDate: DateTime;
dateAppoint: DateTime;
dateStart: DateTime;
dateRetire: DateTime;
isLeave: boolean;
isProbation: boolean;
leaveReason: string;
positionLevel: string;
positionType: string;
educations: ProfileEducationResult[];
leaves: ProfileLeaveResult[];
salaries: ProfileSalaryResult[];
2024-10-17 11:34:03 +07:00
organization: ProfileOrgResult;
2024-10-08 11:47:05 +07:00
}
interface ProfileLeaveResult {
dateLeaveStart: DateTime;
dateLeaveEnd: DateTime;
leaveType: string;
totalLeave: number;
}
2024-10-17 11:34:03 +07:00
interface ProfileOrgResult {
/**
*
*/
orgRootName: string;
/**
* 1
*/
orgChild1Name: string;
/**
* 2
*/
orgChild2Name: string;
/**
* 3
*/
orgChild3Name: string;
/**
* 4
*/
orgChild4Name: string;
}
2024-10-08 11:47:05 +07:00
interface ProfileEducationResult {
country: string;
degree: string;
field: string;
institute: string;
educationLevel: string;
}
interface ProfileSalaryResult {
posNo: string;
position: string;
positionType: string;
positionLevel: string;
amount: Double;
positionSalaryAmount: Double;
monthSalaryAmount: Double;
}
2024-10-07 14:53:27 +07:00
@Route("api/v1/dpis")
@Tags("DPIS")
2024-10-08 11:47:05 +07:00
// @Security("bearerAuth")
2024-10-07 14:53:27 +07:00
@Response(
HttpStatus.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatus.OK, "สำเร็จ")
export class DPISController extends Controller {
private profileRepo = AppDataSource.getRepository(Profile);
2024-10-17 11:34:03 +07:00
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
2024-10-07 14:53:27 +07:00
/**
2024-10-08 11:47:05 +07:00
*
2024-10-07 14:53:27 +07:00
*
2024-10-08 11:47:05 +07:00
* @summary
2024-10-07 14:53:27 +07:00
*
* @param {string} citizenId
*
2024-10-08 11:47:05 +07:00
* @returns
2024-10-07 14:53:27 +07:00
*/
@Get("{citizenId}")
@Example({
2024-10-08 11:47:05 +07:00
status: 200,
message: "Success",
result: {
citizenId: "1103700765894",
prefix: "นาย",
firstName: "สุรศักดิ์",
lastName: "จันทร์ศรี",
gender: "หญิง",
physicalStatus: "ปกติ",
QualityWorkforce: true,
birthDate: "1995-05-06T17:00:00.000Z",
dateAppoint: "2022-11-24T17:00:00.000Z",
dateStart: "2022-11-24T17:00:00.000Z",
dateRetire: "2055-05-06T17:00:00.000Z",
isLeave: false,
isProbation: false,
leaveReason: null,
positionLevel: "ปฏิบัติงาน",
positionType: "ทั่วไป",
2024-10-17 11:34:03 +07:00
organization: {
orgRootName: "",
orgChild1Name: "",
orgChild2Name: "",
orgChild3Name: "",
orgChild4Name: "",
},
2024-10-08 11:47:05 +07:00
educations: [],
salaries: [
{
posNo: "ขพน.65",
position: "เจ้าพนักงานสาธารณสุข",
positionType: "ทั่วไป",
positionLevel: "ปฏิบัติงาน",
amount: 11860,
positionSalaryAmount: 0,
monthSalaryAmount: 0,
},
{
posNo: "ขพน.65",
position:
"เจ้าพนักงานสาธารณสุขปฏิบัติงาน ฝ่ายสิ่งแวดล้อมและสุขาภิบาล สำนักงานเขตพระนคร\n(ทดลองปฏิบัติหน้าที่ราชการ)",
positionType: "ทั่วไป",
positionLevel: "ปฏิบัติงาน",
amount: 11860,
positionSalaryAmount: 0,
monthSalaryAmount: 0,
},
{
posNo: "ขพน.65",
position:
"เจ้าพนักงานสาธารณสุขปฏิบัติงาน ฝ่ายสิ่งแวดล้อมและสุขาภิบาล สำนักงานเขตพระนคร\n(ทดลองปฏิบัติหน้าที่ราชการ)",
positionType: "ทั่วไป",
positionLevel: "ปฏิบัติงาน",
amount: 11500,
positionSalaryAmount: 0,
monthSalaryAmount: 0,
},
],
leaves: [],
2024-10-07 14:53:27 +07:00
},
})
2024-10-08 11:47:05 +07:00
async GetProfileCitizenIdAsync(@Path() citizenId: string): Promise<DPISResponse> {
2024-10-07 14:53:27 +07:00
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
posType: true,
profileSalary: true,
profileEducations: true,
2024-10-08 11:47:05 +07:00
profileLeaves: true,
2024-10-17 11:34:03 +07:00
current_holders: true,
2024-10-07 14:53:27 +07:00
},
where: { citizenId: citizenId },
2024-10-17 11:34:03 +07:00
//relations: ["current_holders", "current_holders.orgRoot"],
2024-10-07 14:53:27 +07:00
order: {
profileSalary: {
date: "DESC",
},
2024-10-08 11:47:05 +07:00
profileLeaves: {
dateLeaveStart: "ASC",
2024-10-07 14:53:27 +07:00
},
profileEducations: {
degree: "ASC",
},
},
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
2024-10-17 11:34:03 +07:00
const findRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true },
});
var current_holder = profile.current_holders?.find((x) => x.orgRevisionId == findRevision?.id);
2024-10-07 14:53:27 +07:00
2024-10-08 11:47:05 +07:00
const mapProfile: DPISResult = {
2024-10-07 14:53:27 +07:00
citizenId: profile.citizenId,
prefix: profile.prefix,
firstName: profile.firstName,
lastName: profile.lastName,
2024-10-08 11:47:05 +07:00
gender: profile.gender,
physicalStatus: "ปกติ",
QualityWorkforce: true,
birthDate: profile.birthDate,
2024-10-07 14:53:27 +07:00
dateAppoint: profile.dateAppoint,
dateStart: profile.dateStart,
2024-10-08 11:47:05 +07:00
dateRetire: profile.dateRetire,
isLeave: profile.isLeave,
isProbation: profile.isProbation,
leaveReason: profile.leaveReason,
positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "",
positionType: profile.posType ? profile.posType.posTypeName : "",
2024-10-17 11:34:03 +07:00
organization: {
orgRootName: current_holder?.orgRoot?.orgRootName || "",
orgChild1Name: current_holder?.orgChild1?.orgChild1Name || "",
orgChild2Name: current_holder?.orgChild2?.orgChild2Name || "",
orgChild3Name: current_holder?.orgChild3?.orgChild3Name || "",
orgChild4Name: current_holder?.orgChild4?.orgChild4Name || "",
},
2024-10-08 11:47:05 +07:00
// educations
educations: profile.profileEducations.map((item) => {
return {
country: item.country,
degree: item.degree,
field: item.field,
institute: item.institute,
educationLevel: item.educationLevel,
};
}),
salaries: profile.profileSalary.map((item) => {
return {
posNo: item.posNo,
position: item.position,
positionType: item.positionType,
positionLevel: item.positionLevel,
amount: item.amount,
positionSalaryAmount: item.positionSalaryAmount,
monthSalaryAmount: item.mouthSalaryAmount,
};
}),
leaves: profile.profileLeaves.map((item) => {
return {
dateLeaveStart: item.dateLeaveStart,
dateLeaveEnd: item.dateLeaveEnd,
leaveType: item.leaveType ? item.leaveType.name : "",
totalLeave: item.totalLeave,
};
}),
2024-10-07 14:53:27 +07:00
};
2024-10-08 11:47:05 +07:00
return {
status: 200,
message: "Success",
result: mapProfile,
};
2024-10-07 14:53:27 +07:00
}
}