diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index b68d98e6..a0485b64 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -548,6 +548,28 @@ export class ProfileController extends Controller { return new HttpSuccess(); } + /** + * API รายละเอียดรายการทะเบียนประวัติ + * + * @summary ORG_065 - รายละเอียดรายการทะเบียนประวัติ (ADMIN) #70 + * + * @param {string} id Id ทะเบียนประวัติ + */ + @Get("user") + async getProfileByUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOne({ + relations: { + posLevel: true, + posType: true, + }, + where: { keycloak: request.user.sub }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + return new HttpSuccess(profile); + } + /** * API รายละเอียดรายการทะเบียนประวัติ * diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index 8ecef4e4..2fd3fc81 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -68,7 +68,7 @@ export class ProfileEmployeeController extends Controller { const orgRevision = await this.orgRevisionRepo.findOne({ where: { orgRevisionIsCurrent: true }, }); - + const profile = await this.profileRepo.findOne({ relations: [ "profileSalarys", @@ -78,16 +78,20 @@ export class ProfileEmployeeController 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 || @@ -123,11 +127,16 @@ export class ProfileEmployeeController extends Controller { ? null : profile.current_holders.find((x) => x.orgRevisionId == orgRevision?.id)?.orgChild4; - let _regisAddres = profile && profile.registrationAddress != null ? profile.registrationAddress : "" - let _subDistrict = subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : "" - let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : "" - let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : "" - let registrationZipCode = profile && profile.registrationZipCode != null ? ` รหัสไปรษณีย์ ${profile.registrationZipCode}` : "" + let _regisAddres = + profile && profile.registrationAddress != null ? profile.registrationAddress : ""; + let _subDistrict = + subDistrict && subDistrict.name != null ? `\r\nตำบล/แขวง ${province?.name}` : ""; + let _district = district && district.name != null ? `\r\nเขต/อำเภอ ${district?.name}` : ""; + let _province = province && province.name != null ? `\r\nจังหวัด ${province?.name}` : ""; + let registrationZipCode = + profile && profile.registrationZipCode != null + ? ` รหัสไปรษณีย์ ${profile.registrationZipCode}` + : ""; let _root = root == null || root == undefined ? "" : `${root.orgRootName}`; let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`; let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`; @@ -140,25 +149,34 @@ export class ProfileEmployeeController extends Controller { Prefix: profile.prefix != null ? profile.prefix : "", FirstName: profile.firstName != null ? profile.firstName : "", LastName: profile.lastName != null ? profile.lastName : "", - DateOfBirth: profile.birthDate != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate)) : "", - DateRetire: profile.dateRetire != null ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire)) : "", + DateOfBirth: + profile.birthDate != null + ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.birthDate)) + : "", + DateRetire: + profile.dateRetire != null + ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.dateRetire)) + : "", RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, - SalaryAmount: profile.profileSalarys.length > 0 && profile.profileSalarys[0].amount != null - ? Extension.ToThaiNumber(profile.profileSalarys[0].amount.toLocaleString()) - : "", - Education: profile.profileEducations.length > 0 && profile.profileEducations[profile.profileEducations.length-1].institute != null - ? profile.profileEducations[profile.profileEducations.length-1].institute - : "", + SalaryAmount: + profile.profileSalarys.length > 0 && profile.profileSalarys[0].amount != null + ? Extension.ToThaiNumber(profile.profileSalarys[0].amount.toLocaleString()) + : "", + Education: + profile.profileEducations.length > 0 && + profile.profileEducations[profile.profileEducations.length - 1].institute != null + ? profile.profileEducations[profile.profileEducations.length - 1].institute + : "", AppointText: profile.dateAppoint != null ? profile.dateAppoint : "", - SalaryDate: profile.profileSalarys.length > 0 && profile.profileSalarys[0].date != null - ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalarys[0].date)) - : "", + SalaryDate: + profile.profileSalarys.length > 0 && profile.profileSalarys[0].date != null + ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalarys[0].date)) + : "", PositionName: profile.position != null ? profile.position : "", OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, - } + }; return new HttpSuccess(mapData); - } /** @@ -349,6 +367,31 @@ export class ProfileEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API รายละเอียดรายการทะเบียนประวัติ + * + * @summary ORG_065 - รายละเอียดรายการทะเบียนประวัติ (ADMIN) #70 + * + * @param {string} id Id ทะเบียนประวัติ + */ + @Get("user") + async detailProfileUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOne({ + relations: { + posLevel: true, + posType: true, + // gender: true, + // relationship: true, + // bloodGroup: true, + }, + where: { keycloak: request.user.sub }, + }); + + if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + + return new HttpSuccess(profile); + } + /** * API รายละเอียดรายการทะเบียนประวัติ * @@ -664,7 +707,7 @@ export class ProfileEmployeeController extends Controller { "profileEmployee.citizenId", "profileSalarys.position", "profileSalarys.posNo", - "profileSalarys.date" + "profileSalarys.date", ]) .andWhere( requestBody.position != null && requestBody.position != "" && requestBody.posNo == undefined @@ -684,24 +727,24 @@ export class ProfileEmployeeController extends Controller { ) .getMany(); - const mapData = profiles.map(profile => { - let profileSalary; - if (profile.profileSalarys && profile.profileSalarys.length > 0) { - profileSalary = profile.profileSalarys.reduce((latest, current) => { - return new Date(current.date) > new Date(latest.date) ? current : latest; - }); - } - return { - id: profile.id, - 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.profileSalarys && profile.profileSalarys.length > 0) { + profileSalary = profile.profileSalarys.reduce((latest, current) => { + return new Date(current.date) > new Date(latest.date) ? current : latest; + }); + } + return { + id: profile.id, + 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); } /** diff --git a/src/controllers/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index 9d9dc0f0..919190af 100644 --- a/src/controllers/ProfileFamilyFatherController.ts +++ b/src/controllers/ProfileFamilyFatherController.ts @@ -50,7 +50,7 @@ export class ProfileFamilyFatherController extends Controller { "fatherLive", "profileId", ], - where: { id: profile.id }, + where: { profileId: profile.id }, order: { lastUpdatedAt: "DESC" }, }); diff --git a/src/controllers/ProfileFamilyHistoryEmployeeController.ts b/src/controllers/ProfileFamilyHistoryEmployeeController.ts index 0289c04f..0315886e 100644 --- a/src/controllers/ProfileFamilyHistoryEmployeeController.ts +++ b/src/controllers/ProfileFamilyHistoryEmployeeController.ts @@ -45,7 +45,7 @@ export class ProfileFamilyHistoryEmployeeController extends Controller { const family = await this.familyHistoryRepo.find({ take: 1, order: { lastUpdatedAt: "DESC" }, - where: { profileId: profile.id }, + where: { profileEmployeeId: profile.id }, }); const children = await this.childrenRepo.find({ order: { createdAt: "ASC" }, diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index d27f2b0e..6cd224b3 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -71,19 +71,19 @@ export class ProfileGovernmentEmployeeController extends Controller { orgChild4: true, }, }); - const position = await this.positionRepo.findOne({ - where: { - positionIsSelected: true, - posMaster: { - orgRevision: { - orgRevisionIsCurrent: true, - orgRevisionIsDraft: false, - }, - current_holderId: profile.id, - }, - }, - order: { createdAt: "DESC" }, - }); + // const position = await this.positionRepo.findOne({ + // where: { + // positionIsSelected: true, + // posMaster: { + // orgRevision: { + // orgRevisionIsCurrent: true, + // orgRevisionIsDraft: false, + // }, + // current_holderId: profile.id, + // }, + // }, + // order: { createdAt: "DESC" }, + // }); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); const fullNameParts = [