add org search
This commit is contained in:
parent
f770b9214a
commit
6ab149f7a3
1 changed files with 59 additions and 0 deletions
|
|
@ -3,6 +3,7 @@ import { Controller, Example, Get, Path, Response, Route, SuccessResponse, Tags
|
|||
import { DateTime } from "@elastic/elasticsearch/lib/api/types";
|
||||
import { Double } from "typeorm";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import HttpError from "../interfaces/http-error";
|
||||
import HttpStatus from "../interfaces/http-status";
|
||||
|
|
@ -12,7 +13,15 @@ interface DPISResponse {
|
|||
* สถานะ
|
||||
*/
|
||||
status: number;
|
||||
|
||||
/**
|
||||
* ข้อความตอบกลับ
|
||||
*/
|
||||
message: string;
|
||||
|
||||
/**
|
||||
* ผลลัพธ์การค้นหา
|
||||
*/
|
||||
result?: DPISResult;
|
||||
}
|
||||
|
||||
|
|
@ -36,6 +45,7 @@ interface DPISResult {
|
|||
educations: ProfileEducationResult[];
|
||||
leaves: ProfileLeaveResult[];
|
||||
salaries: ProfileSalaryResult[];
|
||||
organization: ProfileOrgResult;
|
||||
}
|
||||
|
||||
interface ProfileLeaveResult {
|
||||
|
|
@ -45,6 +55,33 @@ interface ProfileLeaveResult {
|
|||
totalLeave: number;
|
||||
}
|
||||
|
||||
interface ProfileOrgResult {
|
||||
/**
|
||||
* ผลลัพธ์การค้นหา
|
||||
*/
|
||||
orgRootName: string;
|
||||
|
||||
/**
|
||||
* กองระดับ 1
|
||||
*/
|
||||
orgChild1Name: string;
|
||||
|
||||
/**
|
||||
* กองระดับ 2
|
||||
*/
|
||||
orgChild2Name: string;
|
||||
|
||||
/**
|
||||
* กองระดับ 3
|
||||
*/
|
||||
orgChild3Name: string;
|
||||
|
||||
/**
|
||||
* กองระดับ 4
|
||||
*/
|
||||
orgChild4Name: string;
|
||||
}
|
||||
|
||||
interface ProfileEducationResult {
|
||||
country: string;
|
||||
degree: string;
|
||||
|
|
@ -73,6 +110,7 @@ interface ProfileSalaryResult {
|
|||
@SuccessResponse(HttpStatus.OK, "สำเร็จ")
|
||||
export class DPISController extends Controller {
|
||||
private profileRepo = AppDataSource.getRepository(Profile);
|
||||
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
* แสดงข้อมูลข้าราชการจากเลขประจำตัวประชาชน
|
||||
|
|
@ -104,6 +142,13 @@ export class DPISController extends Controller {
|
|||
leaveReason: null,
|
||||
positionLevel: "ปฏิบัติงาน",
|
||||
positionType: "ทั่วไป",
|
||||
organization: {
|
||||
orgRootName: "",
|
||||
orgChild1Name: "",
|
||||
orgChild2Name: "",
|
||||
orgChild3Name: "",
|
||||
orgChild4Name: "",
|
||||
},
|
||||
educations: [],
|
||||
salaries: [
|
||||
{
|
||||
|
|
@ -147,8 +192,10 @@ export class DPISController extends Controller {
|
|||
profileSalary: true,
|
||||
profileEducations: true,
|
||||
profileLeaves: true,
|
||||
current_holders: true,
|
||||
},
|
||||
where: { citizenId: citizenId },
|
||||
//relations: ["current_holders", "current_holders.orgRoot"],
|
||||
order: {
|
||||
profileSalary: {
|
||||
date: "DESC",
|
||||
|
|
@ -162,6 +209,10 @@ export class DPISController extends Controller {
|
|||
},
|
||||
});
|
||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
var current_holder = profile.current_holders?.find((x) => x.orgRevisionId == findRevision?.id);
|
||||
|
||||
const mapProfile: DPISResult = {
|
||||
citizenId: profile.citizenId,
|
||||
|
|
@ -181,6 +232,14 @@ export class DPISController extends Controller {
|
|||
positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "",
|
||||
positionType: profile.posType ? profile.posType.posTypeName : "",
|
||||
|
||||
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 || "",
|
||||
},
|
||||
|
||||
// educations
|
||||
educations: profile.profileEducations.map((item) => {
|
||||
return {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue