From 852525c8f5cd9246ca563302c3b2553fd8e8e86d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 23 May 2024 15:37:13 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=84=E0=B9=89?= =?UTF-8?q?=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88?= =?UTF-8?q?=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/PositionController.ts | 8 ++- src/controllers/ProfileController.ts | 83 ++++++++++++++------------- 2 files changed, 49 insertions(+), 42 deletions(-) diff --git a/src/controllers/PositionController.ts b/src/controllers/PositionController.ts index 476e434b..0c2f7ac7 100644 --- a/src/controllers/PositionController.ts +++ b/src/controllers/PositionController.ts @@ -35,6 +35,8 @@ import { OrgChild4 } from "../entities/OrgChild4"; import { Position } from "../entities/Position"; import { Profile } from "../entities/Profile"; import { EmployeePosMaster } from "../entities/EmployeePosMaster"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; @Route("api/v1/org/pos") @Tags("Position") @Security("bearerAuth") @@ -47,6 +49,8 @@ export class PositionController extends Controller { private posExecutiveRepository = AppDataSource.getRepository(PosExecutive); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private posTypeEmployeeRepository = AppDataSource.getRepository(EmployeePosType); + private posLevelEmployeeRepository = AppDataSource.getRepository(EmployeePosLevel); private posDictRepository = AppDataSource.getRepository(PosDict); private posMasterRepository = AppDataSource.getRepository(PosMaster); private positionRepository = AppDataSource.getRepository(Position); @@ -2759,10 +2763,10 @@ export class PositionController extends Controller { let typeCondition: any = {}; let conditionA: any = null; - let posType = await this.posTypeRepository.findOne({ + let posType = await this.posTypeEmployeeRepository.findOne({ where: { id: String(body.posType) }, }); - let posLevel = await this.posLevelRepository.findOne({ + let posLevel = await this.posLevelEmployeeRepository.findOne({ where: { id: String(body.posLevel) }, }); diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 2c70bf6b..8ca391b1 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -77,7 +77,7 @@ export class ProfileController extends Controller { const orgRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true }, }); - + const profile = await this.profileRepo.findOne({ relations: [ "profileSalary", @@ -87,16 +87,20 @@ export class ProfileController extends Controller { "current_holders.orgChild1", "current_holders.orgChild2", "current_holders.orgChild3", - "current_holders.orgChild4" + "current_holders.orgChild4", ], - where: { id: id, }, + where: { id: id }, }); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - const province = await this.provinceRepository.findOneBy({ id: profile.registrationProvinceId }) - const district = await this.districtRepository.findOneBy({ id: profile.registrationDistrictId }) - const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId }) - + const province = await this.provinceRepository.findOneBy({ + id: profile.registrationProvinceId, + }); + const district = await this.districtRepository.findOneBy({ + id: profile.registrationDistrictId, + }); + const subDistrict = await this.subDistrict.findOneBy({ id: profile.registrationSubDistrictId }); + const root = profile.current_holders == null || profile.current_holders.length == 0 || @@ -147,22 +151,19 @@ export class ProfileController extends Controller { DateOfBirth: profile.birthDate, DateRetire: profile.dateRetire, RegistrationAddress: `${profile.registrationAddress}\r\nตำบล/แขวง ${province?.name}\r\nเขต/อำเภอ ${district?.name}\r\nจังหวัด ${subDistrict?.name} รหัสไปรษณีย์ ${profile.registrationZipCode}`, - SalaryAmount: profile.profileSalary.length > 0 - ? profile.profileSalary[0].amount.toString() - : null, - Education: profile.profileEducations.length > 0 - ? profile.profileEducations[profile.profileEducations.length-1].institute - : null, + SalaryAmount: + profile.profileSalary.length > 0 ? profile.profileSalary[0].amount.toString() : null, + Education: + profile.profileEducations.length > 0 + ? profile.profileEducations[profile.profileEducations.length - 1].institute + : null, AppointText: profile.dateAppoint, - SalaryDate: profile.profileSalary.length > 0 - ? profile.profileSalary[0].date - : null, + SalaryDate: profile.profileSalary.length > 0 ? profile.profileSalary[0].date : null, PositionName: profile.position, OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, - } + }; return new HttpSuccess(mapData); - } /** @@ -945,7 +946,7 @@ export class ProfileController extends Controller { "profile.citizenId", "profileSalary.position", "profileSalary.posNo", - "profileSalary.date" + "profileSalary.date", ]) .andWhere( requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined @@ -965,27 +966,27 @@ export class ProfileController extends Controller { ) .getMany(); - const mapData = profiles.map(profile => { - let profileSalary; - if (profile.profileSalary && profile.profileSalary.length > 0) { - profileSalary = profile.profileSalary.reduce((latest, current) => { - return new Date(current.date) > new Date(latest.date) ? current : latest; - }); - } - return { - id: profile.id, - // prefix: profile.prefix, - // firstName: profile.firstName, - // lastName: profile.lastName, - fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, - citizenId: profile.citizenId, - position: profileSalary ? profileSalary.position : null, - posNo: profileSalary ? profileSalary.posNo : null, - date: profileSalary ? profileSalary.date : null - }; - }); - - return new HttpSuccess(mapData); + const mapData = profiles.map((profile) => { + let profileSalary; + if (profile.profileSalary && profile.profileSalary.length > 0) { + profileSalary = profile.profileSalary.reduce((latest, current) => { + return new Date(current.date) > new Date(latest.date) ? current : latest; + }); + } + return { + id: profile.id, + // prefix: profile.prefix, + // firstName: profile.firstName, + // lastName: profile.lastName, + fullName: `${profile.prefix}${profile.firstName} ${profile.lastName}`, + citizenId: profile.citizenId, + position: profileSalary ? profileSalary.position : null, + posNo: profileSalary ? profileSalary.posNo : null, + date: profileSalary ? profileSalary.date : null, + }; + }); + + return new HttpSuccess(mapData); } /** @@ -1061,6 +1062,8 @@ export class ProfileController extends Controller { profileId: profile.id, prefix: profile.prefix, rank: profile.rank, + avatar: profile.avatar, + avatarName: profile.avatarName, firstName: profile.firstName, lastName: profile.lastName, citizenId: profile.citizenId,