diff --git a/src/controllers/DPISController.ts b/src/controllers/DPISController.ts index 644bd612..597a997b 100644 --- a/src/controllers/DPISController.ts +++ b/src/controllers/DPISController.ts @@ -1,24 +1,68 @@ -import { - Controller, - Example, - Get, - Path, - Response, - Route, - Security, - SuccessResponse, - Tags, -} from "tsoa"; +import { Controller, Example, Get, Path, Response, Route, SuccessResponse, Tags } from "tsoa"; +import { DateTime } from "@elastic/elasticsearch/lib/api/types"; +import { Double } from "typeorm"; import { AppDataSource } from "../database/data-source"; import { Profile } from "../entities/Profile"; import HttpError from "../interfaces/http-error"; import HttpStatus from "../interfaces/http-status"; -import HttpSuccess from "../interfaces/http-success"; + +interface DPISResponse { + status: number; + message: string; + 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[]; +} + +interface ProfileLeaveResult { + dateLeaveStart: DateTime; + dateLeaveEnd: DateTime; + leaveType: string; + totalLeave: number; +} + +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; +} @Route("api/v1/dpis") @Tags("DPIS") -@Security("bearerAuth") +// @Security("bearerAuth") @Response( HttpStatus.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", @@ -28,179 +72,86 @@ export class DPISController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); /** - * 1. API Get Profile จาก เลขประจำตัวประชาชน + * แสดงข้อมูลข้าราชการจากเลขประจำตัวประชาชน * - * @summary 1. API Get Profile จาก เลขประจำตัวประชาชน + * @summary แสดงข้อมูลข้าราชการจากเลขประจำตัวประชาชน * * @param {string} citizenId เลขประจำตัวประชาชน * - * @returns ข้อมูลขปงข้าราชการที่ค้นหาพบในระบบ + * @returns ข้อมูลของข้าราชการที่ค้นหาพบในระบบ */ @Get("{citizenId}") @Example({ - id: "08dc4c9f-2710-4e98-8340-c9f2a65467db", - avatar: null, - avatarName: null, - rank: null, - prefix: "นาย", - firstName: "สุรศักดิ์", - lastName: "จันทร์ศรี", - citizenId: "1103700765894", - position: "เจ้าพนักงานสาธารณสุข", - posLevelId: "1526d9d3-d8b1-43ab-81b5-a84dfbe08262", - email: "userUat43@test.test", - phone: null, - keycloak: "bac99314-8163-4671-9af6-cf994167e939", - isProbation: false, - isLeave: false, - leaveReason: null, - dateRetire: "2055-05-06T17:00:00.000Z", - dateAppoint: "2022-11-24T17:00:00.000Z", - dateRetireLaw: "2055-09-29T17:00:00.000Z", - dateStart: "2022-11-24T17:00:00.000Z", - govAgeAbsent: 0, - govAgePlus: 0, - birthDate: "1995-05-06T17:00:00.000Z", - reasonSameDate: null, - telephoneNumber: "990686659", - nationality: "ไทย", - gender: "หญิง", - relationship: "โสด", - religion: "พุทธ", - bloodGroup: null, - registrationAddress: "21/1 หมู่ที่ 2", - registrationProvinceId: "24bf701c-33d6-436e-ad49-6f82bb3ae029", - registrationDistrictId: "34bf701c-33d6-436e-ad49-6f82bb3b0642", - registrationSubDistrictId: "44bf701c-33d6-436e-ad49-6f82bb3b3427", - registrationZipCode: "22110", - currentAddress: "21/1 หมู่ที่ 2", - currentProvinceId: "24bf701c-33d6-436e-ad49-6f82bb3ae029", - currentSubDistrictId: "44bf701c-33d6-436e-ad49-6f82bb3b3427", - currentZipCode: "22110", - dutyTimeId: null, - dutyTimeEffectiveDate: null, - posLevel: { - id: "1526d9d3-d8b1-43ab-81b5-a84dfbe08262", - createdAt: "2024-01-26T05:42:53.761Z", - createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - lastUpdatedAt: "2024-01-26T05:42:53.761Z", - lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - createdFullName: "สาวิตรี ศรีสมัย", - lastUpdateFullName: "สาวิตรี ศรีสมัย", - posLevelName: "ปฏิบัติงาน", - posLevelRank: 1, - posLevelAuthority: null, - posTypeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe08061", + 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: "ทั่วไป", + 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: [], }, - posType: { - id: "1526d9d3-d8b1-43ab-81b5-a84dfbe08061", - createdAt: "2024-01-26T05:42:53.761Z", - createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - lastUpdatedAt: "2024-08-25T09:41:14.000Z", - lastUpdateUserId: "01378019-5286-4e1d-ae43-826b648af4aa", - createdFullName: "สาวิตรี ศรีสมัย", - lastUpdateFullName: "Super Admin", - posTypeName: "ทั่วไป", - posTypeRank: 1, - }, - profileSalary: [ - { - id: "eef6d0b6-ef64-4389-b497-c74a62e5f334", - createdAt: "2024-08-22T02:23:57.193Z", - createdUserId: "94ba986d-f871-46a2-be92-46c0cbf0bc56", - lastUpdatedAt: "2024-08-22T02:23:57.193Z", - lastUpdateUserId: "94ba986d-f871-46a2-be92-46c0cbf0bc56", - createdFullName: "กานต์พิชชา นาคศรี", - lastUpdateFullName: "กานต์พิชชา นาคศรี", - profileId: "08dc4c9f-2710-4e98-8340-c9f2a65467db", - profileEmployeeId: null, - date: "2024-08-22T09:23:18.000Z", - posNo: "ขพน.65", - position: "เจ้าพนักงานสาธารณสุข", - positionLine: "ปฏิบัติงานสาธารณสุข", - positionPathSide: null, - positionExecutive: null, - positionType: "ทั่วไป", - positionLevel: "ปฏิบัติงาน", - amount: 11860, - positionSalaryAmount: 0, - mouthSalaryAmount: 0, - refCommandNo: null, - templateDoc: "ปรับโครงสร้าง", - order: 3, - }, - { - id: "916fcf0c-f0d5-4efb-af46-0f1942de5c19", - createdAt: "2024-06-27T22:01:25.959Z", - createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - lastUpdatedAt: "2024-06-27T23:24:50.219Z", - lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - createdFullName: "โกศล สิงหนาท", - lastUpdateFullName: "โกศล สิงหนาท", - profileId: "08dc4c9f-2710-4e98-8340-c9f2a65467db", - profileEmployeeId: null, - date: "2023-03-31T17:00:00.000Z", - posNo: "ขพน.65", - position: - "เจ้าพนักงานสาธารณสุขปฏิบัติงาน ฝ่ายสิ่งแวดล้อมและสุขาภิบาล สำนักงานเขตพระนคร\n(ทดลองปฏิบัติหน้าที่ราชการ)", - positionLine: null, - positionPathSide: null, - positionExecutive: null, - positionType: "ทั่วไป", - positionLevel: "ปฏิบัติงาน", - amount: 11860, - positionSalaryAmount: 0, - mouthSalaryAmount: 0, - refCommandNo: null, - templateDoc: "เลื่อนขั้นเงินเดือน คำสั่ง ขพน.ที่ 159/2566 ลว. 6 มิ.ย. 2566", - order: 2, - }, - { - id: "161bea25-0451-4eff-bbfd-709e88a1700f", - createdAt: "2024-06-27T22:01:25.881Z", - createdUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - lastUpdatedAt: "2024-06-27T23:24:50.219Z", - lastUpdateUserId: "59134ef9-9e62-41d0-aac5-339be727f2b0", - createdFullName: "โกศล สิงหนาท", - lastUpdateFullName: "โกศล สิงหนาท", - profileId: "08dc4c9f-2710-4e98-8340-c9f2a65467db", - profileEmployeeId: null, - date: "2022-11-24T17:00:00.000Z", - posNo: "ขพน.65", - position: - "เจ้าพนักงานสาธารณสุขปฏิบัติงาน ฝ่ายสิ่งแวดล้อมและสุขาภิบาล สำนักงานเขตพระนคร\n(ทดลองปฏิบัติหน้าที่ราชการ)", - positionLine: null, - positionPathSide: null, - positionExecutive: null, - positionType: "ทั่วไป", - positionLevel: "ปฏิบัติงาน", - amount: 11500, - positionSalaryAmount: 0, - mouthSalaryAmount: 0, - refCommandNo: null, - templateDoc: - "บรรจุและแต่งตั้งผู้สอบแข่งขันได้ คำสั่ง ขพน.ที่ 374/2565 ลว. 29 พ.ย. 2565 โดยมีเงื่อนไขว่าต้องปฏิบัติงานให้กรุงเทพมหานครเป็นระยะเวลาไม่น้อยกว่า 5 ปี นับแต่วันที่ได้รับการบรรจุและแต่งตั้ง \nโดยห้ามโอนไปหน่วยงานหรือส่วนราชการอื่น เว้นแต่ลาออกจากราชการ\n", - order: 1, - }, - ], - profileInsignia: [], }) - async GetProfileCitizenIdAsync(@Path() citizenId: string) { + async GetProfileCitizenIdAsync(@Path() citizenId: string): Promise { const profile = await this.profileRepo.findOne({ relations: { posLevel: true, posType: true, profileSalary: true, - profileInsignias: true, profileEducations: true, + profileLeaves: true, }, where: { citizenId: citizenId }, order: { profileSalary: { date: "DESC", }, - profileInsignias: { - receiveDate: "DESC", + profileLeaves: { + dateLeaveStart: "ASC", }, profileEducations: { degree: "ASC", @@ -209,45 +160,61 @@ export class DPISController extends Controller { }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - const mapProfile = { + const mapProfile: DPISResult = { citizenId: profile.citizenId, prefix: profile.prefix, firstName: profile.firstName, lastName: profile.lastName, - rank: profile.rank, - position: profile.position, - isProbation: profile.isProbation, - isLeave: profile.isLeave, - leaveReason: profile.leaveReason, - dateRetire: profile.dateRetire, - dateAppoint: profile.dateAppoint, - dateRetireLaw: profile.dateRetireLaw, - dateStart: profile.dateStart, - birthDate: profile.birthDate, - 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, - profileEducation: profile.profileEducations, + physicalStatus: "ปกติ", + QualityWorkforce: true, + birthDate: profile.birthDate, + dateAppoint: profile.dateAppoint, + dateStart: profile.dateStart, + dateRetire: profile.dateRetire, + isLeave: profile.isLeave, + isProbation: profile.isProbation, + leaveReason: profile.leaveReason, + positionLevel: profile.posLevel ? profile.posLevel.posLevelName : "", + positionType: profile.posType ? profile.posType.posTypeName : "", + + // 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, + }; + }), }; - return new HttpSuccess(mapProfile); + return { + status: 200, + message: "Success", + result: mapProfile, + }; } }