From 689d48aadcc114db341f4dfe9763f63dabec6e64 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 23 May 2024 14:10:50 +0700 Subject: [PATCH 1/7] no message --- src/controllers/ProfileController.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index c0873efc..2c70bf6b 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -148,7 +148,7 @@ export class ProfileController extends Controller { 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 + ? profile.profileSalary[0].amount.toString() : null, Education: profile.profileEducations.length > 0 ? profile.profileEducations[profile.profileEducations.length-1].institute From 86fd868adf6c41ef7fbdcdda8674faa2dc73256f Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 23 May 2024 15:28:49 +0700 Subject: [PATCH 2/7] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20quer?= =?UTF-8?q?y=20report?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 40 +++++++++++--------- src/controllers/ProfileEmployeeController.ts | 40 +++++++++++--------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 2c70bf6b..243dc557 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -43,6 +43,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; import { Province } from "../entities/Province"; import { District } from "../entities/District"; import { SubDistrict } from "../entities/SubDistrict"; +import Extension from "../interfaces/extension"; @Route("api/v1/org/profile") @Tags("Profile") @@ -132,6 +133,11 @@ export class ProfileController 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 _root = root == null || root == undefined ? "" : `${root.orgRootName}`; let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`; let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`; @@ -140,24 +146,24 @@ export class ProfileController extends Controller { const mapData = { Id: profile.id, - CitizenId: profile.citizenId, - Prefix: profile.prefix, - FirstName: profile.firstName, - LastName: profile.lastName, - 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 + CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "", + 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)) : "", + RegistrationAddress: `${_regisAddres}${_subDistrict}${_district}${_province}${registrationZipCode}`, + SalaryAmount: profile.profileSalary.length > 0 && profile.profileSalary[0].amount != null + ? Extension.ToThaiNumber(profile.profileSalary[0].amount.toLocaleString()) + : "", + Education: profile.profileEducations.length > 0 && profile.profileEducations[profile.profileEducations.length-1].institute != null ? profile.profileEducations[profile.profileEducations.length-1].institute - : null, - AppointText: profile.dateAppoint, - SalaryDate: profile.profileSalary.length > 0 - ? profile.profileSalary[0].date - : null, - PositionName: profile.position, + : "", + AppointText: profile.dateAppoint != null ? profile.dateAppoint : "", + SalaryDate: profile.profileSalary.length > 0 && profile.profileSalary[0].date != null + ? Extension.ToThaiNumber(Extension.ToThaiFullDate(profile.profileSalary[0].date)) + : "", + PositionName: profile.position != null ? profile.position : "", OcFullPath: `${_child4}${_child3}${_child2}${_child1}${_root}`, } diff --git a/src/controllers/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index ce1b30ae..8ecef4e4 100644 --- a/src/controllers/ProfileEmployeeController.ts +++ b/src/controllers/ProfileEmployeeController.ts @@ -35,6 +35,7 @@ import { Position } from "../entities/Position"; import { Province } from "../entities/Province"; import { District } from "../entities/District"; import { SubDistrict } from "../entities/SubDistrict"; +import Extension from "../interfaces/extension"; @Route("api/v1/org/profile-employee") @Tags("ProfileEmployee") @@ -122,6 +123,11 @@ 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 _root = root == null || root == undefined ? "" : `${root.orgRootName}`; let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`; let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`; @@ -130,24 +136,24 @@ export class ProfileEmployeeController extends Controller { const mapData = { Id: profile.id, - CitizenId: profile.citizenId, - Prefix: profile.prefix, - FirstName: profile.firstName, - LastName: profile.lastName, - 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.profileSalarys.length > 0 - ? profile.profileSalarys[0].amount - : null, - Education: profile.profileEducations.length > 0 + CitizenId: profile.citizenId != null ? Extension.ToThaiNumber(profile.citizenId) : "", + 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)) : "", + 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 - : null, - AppointText: profile.dateAppoint, - SalaryDate: profile.profileSalarys.length > 0 - ? profile.profileSalarys[0].date - : null, - PositionName: profile.position, + : "", + AppointText: profile.dateAppoint != null ? profile.dateAppoint : "", + 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}`, } From 852525c8f5cd9246ca563302c3b2553fd8e8e86d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 23 May 2024 15:37:13 +0700 Subject: [PATCH 3/7] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=84?= =?UTF-8?q?=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=E0=B8=88=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, From ff0be7af48362309b81dd35819a02e5a774ed7c2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 23 May 2024 16:44:37 +0700 Subject: [PATCH 4/7] =?UTF-8?q?get=20=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1?= =?UTF-8?q?=E0=B8=B9=E0=B8=A5=20by=20keycloak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileAbilityController.ts | 15 ++ .../ProfileAbilityEmployeeController.ts | 17 ++- src/controllers/ProfileAddressController.ts | 28 ++++ .../ProfileAssessmentsController.ts | 15 ++ .../ProfileCertificateController.ts | 12 ++ .../ProfileChangeNameController.ts | 30 ++-- src/controllers/ProfileChildrenController.ts | 23 +++- .../ProfileDisciplineController.ts | 23 ++++ src/controllers/ProfileDutyController.ts | 21 +++ .../ProfileEducationsController.ts | 15 ++ .../ProfileFamilyCoupleController.ts | 129 ++++++++++++------ .../ProfileFamilyFatherController.ts | 112 +++++++++------ .../ProfileFamilyHistoryController.ts | 25 ++++ .../ProfileFamilyMotherController.ts | 113 +++++++++------ .../ProfileGovernmentController.ts | 101 ++++++++++++++ src/controllers/ProfileHonorController.ts | 12 ++ src/controllers/ProfileInsigniaController.ts | 17 +++ src/controllers/ProfileLeaveController.ts | 13 ++ src/controllers/ProfileNopaidController.ts | 12 ++ src/controllers/ProfileOtherController.ts | 12 ++ src/controllers/ProfileSalaryController.ts | 13 ++ src/controllers/ProfileTrainingController.ts | 12 ++ 22 files changed, 633 insertions(+), 137 deletions(-) diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index 161f8ae8..facb4d29 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -33,6 +33,21 @@ export class ProfileAbilityController extends Controller { private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility); private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory); + @Get("user") + public async detailProfileAbilityUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAbilityId = await this.profileAbilityRepo.find({ + where: { profileId: profile.id }, + }); + if (!getProfileAbilityId) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAbilityId); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileAbilityEmployeeController.ts b/src/controllers/ProfileAbilityEmployeeController.ts index 5826dfc4..47c56d92 100644 --- a/src/controllers/ProfileAbilityEmployeeController.ts +++ b/src/controllers/ProfileAbilityEmployeeController.ts @@ -35,6 +35,21 @@ export class ProfileAbilityEmployeeController extends Controller { private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility); private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory); + @Get("user") + public async detailProfileAbilityUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAbilityId = await this.profileAbilityRepo.find({ + where: { profileEmployeeId: profile.id }, + }); + if (!getProfileAbilityId) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAbilityId); + } + @Get("{profileEmployeeId}") @Example({ status: 200, @@ -181,7 +196,7 @@ export class ProfileAbilityEmployeeController extends Controller { if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - + return new HttpSuccess(); } } diff --git a/src/controllers/ProfileAddressController.ts b/src/controllers/ProfileAddressController.ts index 9e283744..e2edab5f 100644 --- a/src/controllers/ProfileAddressController.ts +++ b/src/controllers/ProfileAddressController.ts @@ -34,6 +34,34 @@ export class ProfileAddressController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory); + @Get("user") + public async detailProfileAddressUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAddress = await this.profileRepo.findOne({ + where: { id: request.user.sub }, + select: [ + "id", + "registrationAddress", + "registrationProvinceId", + "registrationDistrictId", + "registrationSubDistrictId", + "registrationZipCode", + "currentAddress", + "currentProvinceId", + "currentDistrictId", + "currentSubDistrictId", + "currentZipCode", + ], + }); + if (!getProfileAddress) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAddress); + } + /** * * @summary ข้อมูลที่อยู่ diff --git a/src/controllers/ProfileAssessmentsController.ts b/src/controllers/ProfileAssessmentsController.ts index e261083c..5b008045 100644 --- a/src/controllers/ProfileAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsController.ts @@ -39,6 +39,21 @@ export class ProfileAssessmentsController extends Controller { private profileAssessmentsHistoryRepository = AppDataSource.getRepository(ProfileAssessmentHistory); + @Get("user") + public async detailProfileAssessmentsUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAssessments = await this.profileAssessmentsRepository.find({ + where: { profileId: profile.id }, + }); + if (!getProfileAssessments) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAssessments); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index c21d8db0..56f08974 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -33,6 +33,18 @@ export class ProfileCertificateController extends Controller { private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); + @Get("{profileId}") + public async getCertificateUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.certificateRepo.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index 0d3d0740..8ddf8a86 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -33,6 +33,20 @@ export class ProfileChangeNameController extends Controller { private changeNameRepository = AppDataSource.getRepository(ProfileChangeName); private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory); + @Get("user") + public async getChangeNameUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.changeNameRepository.find({ + where: { profileId: profile.id }, + select: ["id", "prefix", "firstName", "lastName", "status"], + order: { createdAt: "ASC" }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, @@ -158,17 +172,17 @@ export class ProfileChangeNameController extends Controller { ]); const chkLastRecord = await this.changeNameRepository.findOne({ - where:{ - profileId: record.profileId + where: { + profileId: record.profileId, }, - order:{ - createdAt: "DESC" - } - }) + order: { + createdAt: "DESC", + }, + }); if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + const profile = await this.profileRepository.findOneBy({ id: record.profileId }); - + if (profile && chkLastRecord.id === record.id) { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; diff --git a/src/controllers/ProfileChildrenController.ts b/src/controllers/ProfileChildrenController.ts index 36ff9839..f2b4f202 100644 --- a/src/controllers/ProfileChildrenController.ts +++ b/src/controllers/ProfileChildrenController.ts @@ -33,6 +33,18 @@ export class ProfileChildrenController extends Controller { private childrenRepository = AppDataSource.getRepository(ProfileChildren); private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); + @Get("user") + public async getChildrenUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.childrenRepository.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getChildren(@Path() profileId: string) { const lists = await this.childrenRepository.find({ @@ -67,9 +79,9 @@ export class ProfileChildrenController extends Controller { }; Object.assign(data, { ...body, ...meta }); - data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId)); + data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId)); await this.childrenRepository.save(data); - if(data){ + if (data) { const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), { profileChildrenId: data.id, childrenCareer: data.childrenCareer, @@ -102,16 +114,15 @@ export class ProfileChildrenController extends Controller { Object.assign(record, body); record.lastUpdateUserId = req.user.sub; record.lastUpdateFullName = req.user.name; - record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId)); + record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId)); history.profileChildrenId = record.id; history.childrenCareer = record.childrenCareer; history.childrenFirstName = record.childrenFirstName; history.childrenLastName = record.childrenLastName; - history.childrenPrefix = record.childrenPrefix; + history.childrenPrefix = record.childrenPrefix; history.childrenLive = record.childrenLive; history.childrenCitizenId = record.childrenCitizenId; - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.lastUpdateUserId = req.user.sub), (history.lastUpdateFullName = req.user.name); await Promise.all([ this.childrenRepository.save(record), this.childrenHistoryRepository.save(history), diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index cb374bb9..47cd35ed 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -33,6 +33,29 @@ export class ProfileDisciplineController extends Controller { private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); + @Get("user") + public async getDisciplineUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.disciplineRepository.find({ + where: { profileId: profile.id }, + select: [ + "id", + "date", + "level", + "detail", + "unStigma", + "refCommandNo", + "refCommandDate", + "lastUpdateFullName", + "lastUpdatedAt", + ], + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getDiscipline(@Path() profileId: string) { const lists = await this.disciplineRepository.find({ diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index b88754c6..bbea6c69 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -29,6 +29,27 @@ export class ProfileDutyController extends Controller { private dutyRepository = AppDataSource.getRepository(ProfileDuty); private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory); + @Get("user") + public async getDutyUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.dutyRepository.find({ + where: { profileId: profile.id }, + select: [ + "id", + "dateStart", + "dateEnd", + "reference", + "detail", + "refCommandNo", + "refCommandDate", + ], + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index dffba92d..358cf6fa 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -39,6 +39,21 @@ export class ProfileEducationsController extends Controller { private profileEducationRepo = AppDataSource.getRepository(ProfileEducation); private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory); + @Get("user") + public async detailProfileEducationUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileEducation = await this.profileEducationRepo.find({ + where: { profileId: profile.id }, + }); + if (!getProfileEducation) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileEducation); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index 8e23a6a3..039118fe 100644 --- a/src/controllers/ProfileFamilyCoupleController.ts +++ b/src/controllers/ProfileFamilyCoupleController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; -import { ProfileFamilyCouple, CreateProfileFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; +import { + ProfileFamilyCouple, + CreateProfileFamilyCouple, + UpdateProfileFamilyCouple, +} from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile/family/couple") @@ -29,6 +33,32 @@ export class ProfileFamilyCoupleController extends Controller { private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple); private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory); + @Get("user") + public async getFamilyCoupleUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyCouple = await this.ProfileFamilyCouple.findOne({ + select: [ + "id", + "couplePrefix", + "coupleFirstName", + "coupleLastName", + "coupleLastNameOld", + "coupleCareer", + "coupleCitizenId", + "coupleLive", + "relationship", + "profileId", + ], + where: { id: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyCouple); + } + @Get("{profileId}") @Example({ status: 200, @@ -48,16 +78,24 @@ export class ProfileFamilyCoupleController extends Controller { }) public async getFamilyCouple(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyCouple = await this.ProfileFamilyCouple.findOne({ select: [ - "id", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld", - "coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId", + "id", + "couplePrefix", + "coupleFirstName", + "coupleLastName", + "coupleLastNameOld", + "coupleCareer", + "coupleCitizenId", + "coupleLive", + "relationship", + "profileId", ], where: { profileId }, order: { lastUpdatedAt: "DESC" }, @@ -89,13 +127,13 @@ export class ProfileFamilyCoupleController extends Controller { relationship: "string", profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyCoupleHistory(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -103,28 +141,30 @@ export class ProfileFamilyCoupleController extends Controller { const familyCouple = await this.ProfileFamilyCouple.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileId: profileId}, + where: { profileId: profileId }, }); - const mapData = familyCouple.flatMap((x) => x.histories).map((y) => ({ - id: y.id, - createdAt: y.createdAt, - createdUserId: y.createdUserId, - lastUpdatedAt: y.lastUpdatedAt, - lastUpdateUserId: y.lastUpdateUserId, - createdFullName: y.createdFullName, - lastUpdateFullName: y.lastUpdateFullName, - couplePrefix: y.couplePrefix, - coupleFirstName: y.coupleFirstName, - coupleLastName: y.coupleLastName, - coupleLastNameOld: y.coupleLastNameOld, - coupleCareer: y.coupleCareer, - coupleCitizenId: y.coupleCitizenId, - coupleLive: y.coupleLive, - relationship: y.relationship, - profileFamilyCoupleId: y.profileFamilyCoupleId, - profileId: profileId, - })); + const mapData = familyCouple + .flatMap((x) => x.histories) + .map((y) => ({ + id: y.id, + createdAt: y.createdAt, + createdUserId: y.createdUserId, + lastUpdatedAt: y.lastUpdatedAt, + lastUpdateUserId: y.lastUpdateUserId, + createdFullName: y.createdFullName, + lastUpdateFullName: y.lastUpdateFullName, + couplePrefix: y.couplePrefix, + coupleFirstName: y.coupleFirstName, + coupleLastName: y.coupleLastName, + coupleLastNameOld: y.coupleLastNameOld, + coupleCareer: y.coupleCareer, + coupleCitizenId: y.coupleCitizenId, + coupleLive: y.coupleLive, + relationship: y.relationship, + profileFamilyCoupleId: y.profileFamilyCoupleId, + profileId: profileId, + })); return new HttpSuccess(mapData); } @@ -142,7 +182,7 @@ export class ProfileFamilyCoupleController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); + familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); familyCouple.createdUserId = req.user.sub; familyCouple.createdFullName = req.user.name; familyCouple.lastUpdateUserId = req.user.sub; @@ -150,7 +190,7 @@ export class ProfileFamilyCoupleController extends Controller { await this.ProfileFamilyCouple.save(familyCouple); if (familyCouple) { - profile.relationship = familyCouple.relationship //update profile.relationship + profile.relationship = familyCouple.relationship; //update profile.relationship const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), { profileFamilyCoupleId: familyCouple.id, couplePrefix: familyCouple.couplePrefix, @@ -168,7 +208,7 @@ export class ProfileFamilyCoupleController extends Controller { }); await Promise.all([ this.profileRepo.save(profile), - this.ProfileFamilyCoupleHistory.save(history) + this.ProfileFamilyCoupleHistory.save(history), ]); } return new HttpSuccess(familyCouple.id); @@ -186,20 +226,20 @@ export class ProfileFamilyCoupleController extends Controller { const history = new ProfileFamilyCoupleHistory(); Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(familyCouple, body); - familyCouple.lastUpdateUserId = req.user.sub, - familyCouple.lastUpdateFullName = req.user.name; - familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); + (familyCouple.lastUpdateUserId = req.user.sub), + (familyCouple.lastUpdateFullName = req.user.name); + familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); history.profileFamilyCoupleId = familyCouple.id; - history.couplePrefix = familyCouple.couplePrefix, - history.coupleFirstName = familyCouple.coupleFirstName, - history.coupleLastName = familyCouple.coupleLastName, - history.coupleLastNameOld = familyCouple.coupleLastNameOld, - history.coupleCareer = familyCouple.coupleCareer, - history.coupleCitizenId = familyCouple.coupleCitizenId, - history.coupleLive = familyCouple.coupleLive, - history.relationship = familyCouple.relationship, - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.couplePrefix = familyCouple.couplePrefix), + (history.coupleFirstName = familyCouple.coupleFirstName), + (history.coupleLastName = familyCouple.coupleLastName), + (history.coupleLastNameOld = familyCouple.coupleLastNameOld), + (history.coupleCareer = familyCouple.coupleCareer), + (history.coupleCitizenId = familyCouple.coupleCitizenId), + (history.coupleLive = familyCouple.coupleLive), + (history.relationship = familyCouple.relationship), + (history.lastUpdateUserId = req.user.sub), + (history.lastUpdateFullName = req.user.name); await Promise.all([ this.ProfileFamilyCouple.save(familyCouple), @@ -208,5 +248,4 @@ export class ProfileFamilyCoupleController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index fd20707b..9d9dc0f0 100644 --- a/src/controllers/ProfileFamilyFatherController.ts +++ b/src/controllers/ProfileFamilyFatherController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; -import { ProfileFamilyFather, CreateProfileFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather"; +import { + ProfileFamilyFather, + CreateProfileFamilyFather, + UpdateProfileFamilyFather, +} from "../entities/ProfileFamilyFather"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile/family/father") @@ -29,6 +33,30 @@ export class ProfileFamilyFatherController extends Controller { private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather); private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory); + @Get("user") + public async getFamilyFatherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyFather = await this.ProfileFamilyFather.findOne({ + select: [ + "id", + "fatherPrefix", + "fatherFirstName", + "fatherLastName", + "fatherCareer", + "fatherCitizenId", + "fatherLive", + "profileId", + ], + where: { id: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyFather); + } + @Get("{profileId}") @Example({ status: 200, @@ -46,16 +74,22 @@ export class ProfileFamilyFatherController extends Controller { }) public async getFamilyFather(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyFather = await this.ProfileFamilyFather.findOne({ select: [ - "id", "fatherPrefix", "fatherFirstName", "fatherLastName", - "fatherCareer", "fatherCitizenId", "fatherLive", "profileId", + "id", + "fatherPrefix", + "fatherFirstName", + "fatherLastName", + "fatherCareer", + "fatherCitizenId", + "fatherLive", + "profileId", ], where: { profileId }, order: { lastUpdatedAt: "DESC" }, @@ -85,13 +119,13 @@ export class ProfileFamilyFatherController extends Controller { fatherLive: true, profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyFatherHistory(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -99,26 +133,28 @@ export class ProfileFamilyFatherController extends Controller { const familyFather = await this.ProfileFamilyFather.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileId: profileId}, + where: { profileId: profileId }, }); - const mapData = familyFather.flatMap((x) => x.histories).map((y) => ({ - id: y.id, - createdAt: y.createdAt, - createdUserId: y.createdUserId, - lastUpdatedAt: y.lastUpdatedAt, - lastUpdateUserId: y.lastUpdateUserId, - createdFullName: y.createdFullName, - lastUpdateFullName: y.lastUpdateFullName, - fatherPrefix: y.fatherPrefix, - fatherFirstName: y.fatherFirstName, - fatherLastName: y.fatherLastName, - fatherCareer: y.fatherCareer, - fatherCitizenId: y.fatherCitizenId, - fatherLive: y.fatherLive, - profileFamilyFatherId: y.profileFamilyFatherId, - profileId: profileId, - })); + const mapData = familyFather + .flatMap((x) => x.histories) + .map((y) => ({ + id: y.id, + createdAt: y.createdAt, + createdUserId: y.createdUserId, + lastUpdatedAt: y.lastUpdatedAt, + lastUpdateUserId: y.lastUpdateUserId, + createdFullName: y.createdFullName, + lastUpdateFullName: y.lastUpdateFullName, + fatherPrefix: y.fatherPrefix, + fatherFirstName: y.fatherFirstName, + fatherLastName: y.fatherLastName, + fatherCareer: y.fatherCareer, + fatherCitizenId: y.fatherCitizenId, + fatherLive: y.fatherLive, + profileFamilyFatherId: y.profileFamilyFatherId, + profileId: profileId, + })); return new HttpSuccess(mapData); } @@ -136,7 +172,7 @@ export class ProfileFamilyFatherController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); + familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.createdUserId = req.user.sub; familyFather.createdFullName = req.user.name; familyFather.lastUpdateUserId = req.user.sub; @@ -174,18 +210,18 @@ export class ProfileFamilyFatherController extends Controller { const history = new ProfileFamilyFatherHistory(); Object.assign(history, { ...familyFather, id: undefined }); Object.assign(familyFather, body); - familyFather.lastUpdateUserId = req.user.sub, - familyFather.lastUpdateFullName = req.user.name; - familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); + (familyFather.lastUpdateUserId = req.user.sub), + (familyFather.lastUpdateFullName = req.user.name); + familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); history.profileFamilyFatherId = familyFather.id; //profileFamilyFatherId - history.fatherPrefix = familyFather.fatherPrefix, - history.fatherFirstName = familyFather.fatherFirstName, - history.fatherLastName = familyFather.fatherLastName, - history.fatherCareer = familyFather.fatherCareer, - history.fatherCitizenId = familyFather.fatherCitizenId, - history.fatherLive = familyFather.fatherLive, - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.fatherPrefix = familyFather.fatherPrefix), + (history.fatherFirstName = familyFather.fatherFirstName), + (history.fatherLastName = familyFather.fatherLastName), + (history.fatherCareer = familyFather.fatherCareer), + (history.fatherCitizenId = familyFather.fatherCitizenId), + (history.fatherLive = familyFather.fatherLive), + (history.lastUpdateUserId = req.user.sub), + (history.lastUpdateFullName = req.user.name); await Promise.all([ this.ProfileFamilyFather.save(familyFather), diff --git a/src/controllers/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 6d696560..1ea363ea 100644 --- a/src/controllers/ProfileFamilyHistoryController.ts +++ b/src/controllers/ProfileFamilyHistoryController.ts @@ -36,6 +36,31 @@ export class ProfileFamilyHistoryController extends Controller { private childrenRepo = AppDataSource.getRepository(ProfileChildren); private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory); + @Get("user") + public async getFamilyHistoryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const family = await this.familyHistoryRepo.find({ + take: 1, + order: { lastUpdatedAt: "DESC" }, + where: { id: profile.id }, + }); + const children = await this.childrenRepo.find({ + order: { createdAt: "ASC" }, + where: { id: profile.id }, + }); + return new HttpSuccess( + family.length > 0 + ? { + ...family[0], + children, + } + : null, + ); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index 122fe977..879b7795 100644 --- a/src/controllers/ProfileFamilyMotherController.ts +++ b/src/controllers/ProfileFamilyMotherController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; -import { ProfileFamilyMother, CreateProfileFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother"; +import { + ProfileFamilyMother, + CreateProfileFamilyMother, + UpdateProfileFamilyMother, +} from "../entities/ProfileFamilyMother"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile/family/mother") @@ -29,6 +33,30 @@ export class ProfileFamilyMotherController extends Controller { private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother); private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory); + @Get("user") + public async getFamilyMotherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyMother = await this.ProfileFamilyMother.findOne({ + select: [ + "id", + "motherPrefix", + "motherFirstName", + "motherLastName", + "motherCareer", + "motherCitizenId", + "motherLive", + "profileId", + ], + where: { id: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyMother); + } + @Get("{profileId}") @Example({ status: 200, @@ -46,16 +74,22 @@ export class ProfileFamilyMotherController extends Controller { }) public async getFamilyMother(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyMother = await this.ProfileFamilyMother.findOne({ select: [ - "id", "motherPrefix", "motherFirstName", "motherLastName", - "motherCareer", "motherCitizenId", "motherLive", "profileId", + "id", + "motherPrefix", + "motherFirstName", + "motherLastName", + "motherCareer", + "motherCitizenId", + "motherLive", + "profileId", ], where: { profileId }, order: { lastUpdatedAt: "DESC" }, @@ -85,13 +119,13 @@ export class ProfileFamilyMotherController extends Controller { motherLive: true, profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyMotherHistory(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -99,26 +133,28 @@ export class ProfileFamilyMotherController extends Controller { const familyMother = await this.ProfileFamilyMother.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileId: profileId}, + where: { profileId: profileId }, }); - const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({ - id: y.id, - createdAt: y.createdAt, - createdUserId: y.createdUserId, - lastUpdatedAt: y.lastUpdatedAt, - lastUpdateUserId: y.lastUpdateUserId, - createdFullName: y.createdFullName, - lastUpdateFullName: y.lastUpdateFullName, - motherPrefix: y.motherPrefix, - motherFirstName: y.motherFirstName, - motherLastName: y.motherLastName, - motherCareer: y.motherCareer, - motherCitizenId: y.motherCitizenId, - motherLive: y.motherLive, - profileFamilyMotherId: y.profileFamilyMotherId, - profileId: profileId, - })); + const mapData = familyMother + .flatMap((x) => x.histories) + .map((y) => ({ + id: y.id, + createdAt: y.createdAt, + createdUserId: y.createdUserId, + lastUpdatedAt: y.lastUpdatedAt, + lastUpdateUserId: y.lastUpdateUserId, + createdFullName: y.createdFullName, + lastUpdateFullName: y.lastUpdateFullName, + motherPrefix: y.motherPrefix, + motherFirstName: y.motherFirstName, + motherLastName: y.motherLastName, + motherCareer: y.motherCareer, + motherCitizenId: y.motherCitizenId, + motherLive: y.motherLive, + profileFamilyMotherId: y.profileFamilyMotherId, + profileId: profileId, + })); return new HttpSuccess(mapData); } @@ -136,7 +172,7 @@ export class ProfileFamilyMotherController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); + familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.createdUserId = req.user.sub; familyMother.createdFullName = req.user.name; familyMother.lastUpdateUserId = req.user.sub; @@ -174,18 +210,18 @@ export class ProfileFamilyMotherController extends Controller { const history = new ProfileFamilyMotherHistory(); Object.assign(history, { ...familyMother, id: undefined }); Object.assign(familyMother, body); - familyMother.lastUpdateUserId = req.user.sub, - familyMother.lastUpdateFullName = req.user.name; - familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); + (familyMother.lastUpdateUserId = req.user.sub), + (familyMother.lastUpdateFullName = req.user.name); + familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); history.profileFamilyMotherId = familyMother.id; - history.motherPrefix = familyMother.motherPrefix, - history.motherFirstName = familyMother.motherFirstName, - history.motherLastName = familyMother.motherLastName, - history.motherCareer = familyMother.motherCareer, - history.motherCitizenId = familyMother.motherCitizenId, - history.motherLive = familyMother.motherLive, - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.motherPrefix = familyMother.motherPrefix), + (history.motherFirstName = familyMother.motherFirstName), + (history.motherLastName = familyMother.motherLastName), + (history.motherCareer = familyMother.motherCareer), + (history.motherCitizenId = familyMother.motherCitizenId), + (history.motherLive = familyMother.motherLive), + (history.lastUpdateUserId = req.user.sub), + (history.lastUpdateFullName = req.user.name); await Promise.all([ this.ProfileFamilyMother.save(familyMother), @@ -194,5 +230,4 @@ export class ProfileFamilyMotherController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 02a5a128..68d09879 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -19,6 +19,107 @@ export class ProfileGovernmentHistoryController extends Controller { private positionRepo = AppDataSource.getRepository(Position); private posMasterRepo = AppDataSource.getRepository(PosMaster); + /** + * + * @summary ข้อมูลราชการ + * + */ + @Get("user") + public async getGovHistoryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileRepo.findOne({ + where: { id: profile.id }, + relations: { + posType: true, + posLevel: true, + }, + }); + const posMaster = await this.posMasterRepo.findOne({ + where: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + current_holderId: profile.id, + }, + order: { createdAt: "DESC" }, + relations: { + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + }, + }); + const position = await this.positionRepo.findOne({ + where: { + positionIsSelected: true, + posMaster: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + current_holderId: profile.id, + }, + }, + order: { createdAt: "DESC" }, + relations: { + posExecutive: true, + }, + }); + + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const fullNameParts = [ + posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, + posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, + posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name, + posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name, + posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName, + ]; + const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/"); + let orgShortName = ""; + if (posMaster != null) { + if (posMaster.orgChild1Id === null) { + orgShortName = posMaster.orgRoot?.orgRootShortName; + } else if (posMaster.orgChild2Id === null) { + orgShortName = posMaster.orgChild1?.orgChild1ShortName; + } else if (posMaster.orgChild3Id === null) { + orgShortName = posMaster.orgChild2?.orgChild2ShortName; + } else if (posMaster.orgChild4Id === null) { + orgShortName = posMaster.orgChild3?.orgChild3ShortName; + } else { + orgShortName = posMaster.orgChild4?.orgChild4ShortName; + } + } + const data = { + org: org, //สังกัด + positionField: position == null ? null : position.positionField, //สายงาน + position: record.position, //ตำแหน่ง + posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ + posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + posExecutive: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร + positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา + positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร + dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), + dateRetireLaw: record.dateRetireLaw ?? null, + govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateAppoint: record.dateAppoint, + dateStart: record.dateStart, + govAgeAbsent: record.govAgeAbsent, + govAgePlus: record.govAgePlus, + reasonSameDate: record.reasonSameDate, + }; + + return new HttpSuccess(data); + } + /** * * @summary ข้อมูลราชการ diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index 9a03daa3..a66fa2d6 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -29,6 +29,18 @@ export class ProfileHonorController extends Controller { private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); + @Get("user") + public async getHonorUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.honorRepo.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index a83e97a0..1f1d9ec3 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -35,6 +35,23 @@ export class ProfileInsigniaController extends Controller { private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaMetaRepo = AppDataSource.getRepository(Insignia); + @Get("user") + public async getInsigniaUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.insigniaRepo.find({ + relations: { + insignia: { + insigniaType: true, + }, + }, + where: { id: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 6510dff1..07289054 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -36,6 +36,19 @@ export class ProfileLeaveController extends Controller { private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory); private leaveTypeRepository = AppDataSource.getRepository(LeaveType); + @Get("user") + public async getLeaveUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.leaveRepo.find({ + relations: { leaveType: true }, + where: { id: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index d2a531fd..d79a0f0b 100644 --- a/src/controllers/ProfileNopaidController.ts +++ b/src/controllers/ProfileNopaidController.ts @@ -29,6 +29,18 @@ export class ProfileNopaidController extends Controller { private nopaidRepository = AppDataSource.getRepository(ProfileNopaid); private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory); + @Get("user") + public async getNopaidUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.nopaidRepository.find({ + where: { id: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index 1a4eeeed..5737a12d 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -29,6 +29,18 @@ export class ProfileOtherController extends Controller { private otherRepository = AppDataSource.getRepository(ProfileOther); private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory); + @Get("user") + public async getOtherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.otherRepository.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index ebc6c27a..cf565bcc 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -30,6 +30,19 @@ export class ProfileSalaryController extends Controller { private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); + @Get("user") + public async getSalaryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.salaryRepo.find({ + where: { profileId: profile.id }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index 00585eca..4c9b20a7 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -33,6 +33,18 @@ export class ProfileTrainingController extends Controller { private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); + @Get("user") + public async getTrainingUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.trainingRepo.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, From 24c5cbef55143814d21020dc8fb770684cf2f554 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 23 May 2024 17:20:15 +0700 Subject: [PATCH 5/7] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=84?= =?UTF-8?q?=E0=B9=89=E0=B8=99=E0=B8=AB=E0=B8=B2=E0=B8=9B=E0=B8=A3=E0=B8=B0?= =?UTF-8?q?=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=20by=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileAddressController.ts | 2 +- src/controllers/ProfileCertificateController.ts | 2 +- src/controllers/ProfileFamilyHistoryController.ts | 4 ++-- src/controllers/ProfileFamilyMotherController.ts | 2 +- src/controllers/ProfileInsigniaController.ts | 2 +- src/controllers/ProfileLeaveController.ts | 2 +- src/controllers/ProfileNopaidController.ts | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/controllers/ProfileAddressController.ts b/src/controllers/ProfileAddressController.ts index e2edab5f..497d45b7 100644 --- a/src/controllers/ProfileAddressController.ts +++ b/src/controllers/ProfileAddressController.ts @@ -41,7 +41,7 @@ export class ProfileAddressController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const getProfileAddress = await this.profileRepo.findOne({ - where: { id: request.user.sub }, + where: { id: profile.id }, select: [ "id", "registrationAddress", diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index 56f08974..10185798 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -33,7 +33,7 @@ export class ProfileCertificateController extends Controller { private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); - @Get("{profileId}") + @Get("user") public async getCertificateUser(@Request() request: { user: Record }) { const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); if (!profile) { diff --git a/src/controllers/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 1ea363ea..7928ef92 100644 --- a/src/controllers/ProfileFamilyHistoryController.ts +++ b/src/controllers/ProfileFamilyHistoryController.ts @@ -45,11 +45,11 @@ export class ProfileFamilyHistoryController extends Controller { const family = await this.familyHistoryRepo.find({ take: 1, order: { lastUpdatedAt: "DESC" }, - where: { id: profile.id }, + where: { profileId: profile.id }, }); const children = await this.childrenRepo.find({ order: { createdAt: "ASC" }, - where: { id: profile.id }, + where: { profileId: profile.id }, }); return new HttpSuccess( family.length > 0 diff --git a/src/controllers/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index 879b7795..cad827d2 100644 --- a/src/controllers/ProfileFamilyMotherController.ts +++ b/src/controllers/ProfileFamilyMotherController.ts @@ -50,7 +50,7 @@ export class ProfileFamilyMotherController extends Controller { "motherLive", "profileId", ], - where: { id: profile.id }, + where: { profileId: profile.id }, order: { lastUpdatedAt: "DESC" }, }); diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 1f1d9ec3..184d3307 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -47,7 +47,7 @@ export class ProfileInsigniaController extends Controller { insigniaType: true, }, }, - where: { id: profile.id }, + where: { profileId: profile.id }, }); return new HttpSuccess(record); } diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 07289054..60e866b2 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -44,7 +44,7 @@ export class ProfileLeaveController extends Controller { } const record = await this.leaveRepo.find({ relations: { leaveType: true }, - where: { id: profile.id }, + where: { profileId: profile.id }, }); return new HttpSuccess(record); } diff --git a/src/controllers/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index d79a0f0b..06b163d8 100644 --- a/src/controllers/ProfileNopaidController.ts +++ b/src/controllers/ProfileNopaidController.ts @@ -36,7 +36,7 @@ export class ProfileNopaidController extends Controller { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const lists = await this.nopaidRepository.find({ - where: { id: profile.id }, + where: { profileId: profile.id }, }); return new HttpSuccess(lists); } From 58fe2f08fdfbec86f47af61b5814cbc6ea975911 Mon Sep 17 00:00:00 2001 From: Bright Date: Thu, 23 May 2024 18:30:16 +0700 Subject: [PATCH 6/7] =?UTF-8?q?get=20=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1?= =?UTF-8?q?=E0=B8=B9=E0=B8=A5=20by=20keycloak=20(=E0=B8=A5=E0=B8=B9?= =?UTF-8?q?=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProfileAddressEmployeeController.ts | 28 ++++++ .../ProfileAssessmentsEmployeeController.ts | 18 +++- .../ProfileCertificateEmployeeController.ts | 12 +++ .../ProfileChangeNameEmployeeController.ts | 14 +++ .../ProfileChildrenEmployeeController.ts | 12 +++ .../ProfileDisciplineEmployeeController.ts | 23 +++++ .../ProfileDutyEmployeeController.ts | 21 +++++ .../ProfileEducationsEmployeeController.ts | 15 +++ .../ProfileFamilyCoupleController.ts | 2 +- .../ProfileFamilyCoupleEmployeeController.ts | 26 ++++++ .../ProfileFamilyFatherEmployeeController.ts | 24 +++++ .../ProfileFamilyHistoryEmployeeController.ts | 25 +++++ .../ProfileFamilyMotherEmployeeController.ts | 24 +++++ .../ProfileGovernmentEmployeeController.ts | 91 +++++++++++++++++++ .../ProfileHonorEmployeeController.ts | 12 +++ .../ProfileInsigniaEmployeeController.ts | 17 ++++ .../ProfileLeaveEmployeeController.ts | 13 +++ .../ProfileNopaidEmployeeController.ts | 12 +++ .../ProfileOtherEmployeeController.ts | 12 +++ .../ProfileSalaryEmployeeController.ts | 13 +++ .../ProfileTrainingEmployeeController.ts | 12 +++ 21 files changed, 423 insertions(+), 3 deletions(-) diff --git a/src/controllers/ProfileAddressEmployeeController.ts b/src/controllers/ProfileAddressEmployeeController.ts index 12e11049..b6f4aced 100644 --- a/src/controllers/ProfileAddressEmployeeController.ts +++ b/src/controllers/ProfileAddressEmployeeController.ts @@ -35,6 +35,34 @@ export class ProfileAddressEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory); + @Get("user") + public async detailProfileAddressUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAddress = await this.profileEmployeeRepo.findOne({ + where: { id: profile.id }, + select: [ + "id", + "registrationAddress", + "registrationProvinceId", + "registrationDistrictId", + "registrationSubDistrictId", + "registrationZipCode", + "currentAddress", + "currentProvinceId", + "currentDistrictId", + "currentSubDistrictId", + "currentZipCode", + ], + }); + if (!getProfileAddress) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAddress); + } + /** * * @summary ข้อมูลที่อยู่ diff --git a/src/controllers/ProfileAssessmentsEmployeeController.ts b/src/controllers/ProfileAssessmentsEmployeeController.ts index 4f65867d..ef2fad00 100644 --- a/src/controllers/ProfileAssessmentsEmployeeController.ts +++ b/src/controllers/ProfileAssessmentsEmployeeController.ts @@ -36,8 +36,22 @@ import { RequestWithUser } from "../middlewares/user"; export class ProfileAssessmentsEmployeeController extends Controller { private profileEmployeeRepo = AppDataSource.getRepository(ProfileEmployee); private profileAssessmentsRepository = AppDataSource.getRepository(ProfileAssessment); - private profileAssessmentsHistoryRepository = - AppDataSource.getRepository(ProfileAssessmentHistory); + private profileAssessmentsHistoryRepository = AppDataSource.getRepository(ProfileAssessmentHistory); + + @Get("user") + public async detailProfileAssessmentsUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAssessments = await this.profileAssessmentsRepository.find({ + where: { profileEmployeeId: profile.id }, + }); + if (!getProfileAssessments) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAssessments); + } @Get("{profileEmployeeId}") @Example({ diff --git a/src/controllers/ProfileCertificateEmployeeController.ts b/src/controllers/ProfileCertificateEmployeeController.ts index 255d38af..5fbcfc55 100644 --- a/src/controllers/ProfileCertificateEmployeeController.ts +++ b/src/controllers/ProfileCertificateEmployeeController.ts @@ -33,6 +33,18 @@ export class ProfileCertificateEmployeeController extends Controller { private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); + @Get("user") + public async getCertificateUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.certificateRepo.find({ + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index cfbc377e..244a0fd1 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -35,6 +35,20 @@ export class ProfileChangeNameEmployeeController extends Controller { private changeNameRepository = AppDataSource.getRepository(ProfileChangeName); private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory); + @Get("user") + public async getChangeNameUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.changeNameRepository.find({ + where: { profileEmployeeId: profile.id }, + select: ["id", "prefix", "firstName", "lastName", "status"], + order: { createdAt: "ASC" }, + }); + return new HttpSuccess(lists); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileChildrenEmployeeController.ts b/src/controllers/ProfileChildrenEmployeeController.ts index 9fe7945f..a515c896 100644 --- a/src/controllers/ProfileChildrenEmployeeController.ts +++ b/src/controllers/ProfileChildrenEmployeeController.ts @@ -35,6 +35,18 @@ export class ProfileChildrenEmployeeController extends Controller { private childrenRepository = AppDataSource.getRepository(ProfileChildren); private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); + @Get("user") + public async getChildrenUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.childrenRepository.find({ + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileEmployeeId}") public async getChildren(@Path() profileEmployeeId: string) { const lists = await this.childrenRepository.find({ diff --git a/src/controllers/ProfileDisciplineEmployeeController.ts b/src/controllers/ProfileDisciplineEmployeeController.ts index 9ed528c8..4819c9f3 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -33,6 +33,29 @@ export class ProfileDisciplineEmployeeController extends Controller { private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); + @Get("user") + public async getDisciplineUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.disciplineRepository.find({ + where: { profileEmployeeId: profile.id }, + select: [ + "id", + "date", + "level", + "detail", + "unStigma", + "refCommandNo", + "refCommandDate", + "lastUpdateFullName", + "lastUpdatedAt", + ], + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileDutyEmployeeController.ts b/src/controllers/ProfileDutyEmployeeController.ts index 70077ec3..0a435c92 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -29,6 +29,27 @@ export class ProfileDutyEmployeeController extends Controller { private dutyRepository = AppDataSource.getRepository(ProfileDuty); private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory); + @Get("user") + public async getDutyUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.dutyRepository.find({ + where: { profileEmployeeId: profile.id }, + select: [ + "id", + "dateStart", + "dateEnd", + "reference", + "detail", + "refCommandNo", + "refCommandDate", + ], + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getDuty(@Path() profileId: string) { const lists = await this.dutyRepository.find({ diff --git a/src/controllers/ProfileEducationsEmployeeController.ts b/src/controllers/ProfileEducationsEmployeeController.ts index 83a38bc2..eececfbf 100644 --- a/src/controllers/ProfileEducationsEmployeeController.ts +++ b/src/controllers/ProfileEducationsEmployeeController.ts @@ -41,6 +41,21 @@ export class ProfileEducationsEmployeeController extends Controller { private profileEducationRepo = AppDataSource.getRepository(ProfileEducation); private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory); + @Get("user") + public async detailProfileEducationUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileEducation = await this.profileEducationRepo.find({ + where: { profileEmployeeId: profile.id }, + }); + if (!getProfileEducation) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileEducation); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index 039118fe..a3b76cfa 100644 --- a/src/controllers/ProfileFamilyCoupleController.ts +++ b/src/controllers/ProfileFamilyCoupleController.ts @@ -52,7 +52,7 @@ export class ProfileFamilyCoupleController extends Controller { "relationship", "profileId", ], - where: { id: profile.id }, + where: { profileId: profile.id }, order: { lastUpdatedAt: "DESC" }, }); diff --git a/src/controllers/ProfileFamilyCoupleEmployeeController.ts b/src/controllers/ProfileFamilyCoupleEmployeeController.ts index f37b93c5..4ccca644 100644 --- a/src/controllers/ProfileFamilyCoupleEmployeeController.ts +++ b/src/controllers/ProfileFamilyCoupleEmployeeController.ts @@ -29,6 +29,32 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple); private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory); + @Get("user") + public async getFamilyCoupleUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyCouple = await this.ProfileFamilyCouple.findOne({ + select: [ + "id", + "couplePrefix", + "coupleFirstName", + "coupleLastName", + "coupleLastNameOld", + "coupleCareer", + "coupleCitizenId", + "coupleLive", + "relationship", + "profileId", + ], + where: { profileEmployeeId: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyCouple); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyFatherEmployeeController.ts b/src/controllers/ProfileFamilyFatherEmployeeController.ts index 67fbae04..07bdbb39 100644 --- a/src/controllers/ProfileFamilyFatherEmployeeController.ts +++ b/src/controllers/ProfileFamilyFatherEmployeeController.ts @@ -29,6 +29,30 @@ export class ProfileFamilyFatherEmployeeController extends Controller { private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather); private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory); + @Get("user") + public async getFamilyFatherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyFather = await this.ProfileFamilyFather.findOne({ + select: [ + "id", + "fatherPrefix", + "fatherFirstName", + "fatherLastName", + "fatherCareer", + "fatherCitizenId", + "fatherLive", + "profileId", + ], + where: { profileEmployeeId: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyFather); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyHistoryEmployeeController.ts b/src/controllers/ProfileFamilyHistoryEmployeeController.ts index ce34730d..0289c04f 100644 --- a/src/controllers/ProfileFamilyHistoryEmployeeController.ts +++ b/src/controllers/ProfileFamilyHistoryEmployeeController.ts @@ -36,6 +36,31 @@ export class ProfileFamilyHistoryEmployeeController extends Controller { private childrenRepo = AppDataSource.getRepository(ProfileChildren); private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory); + @Get("user") + public async getFamilyHistoryUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const family = await this.familyHistoryRepo.find({ + take: 1, + order: { lastUpdatedAt: "DESC" }, + where: { profileId: profile.id }, + }); + const children = await this.childrenRepo.find({ + order: { createdAt: "ASC" }, + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess( + family.length > 0 + ? { + ...family[0], + children, + } + : null, + ); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyMotherEmployeeController.ts b/src/controllers/ProfileFamilyMotherEmployeeController.ts index 21ece9f7..4afcc1e7 100644 --- a/src/controllers/ProfileFamilyMotherEmployeeController.ts +++ b/src/controllers/ProfileFamilyMotherEmployeeController.ts @@ -29,6 +29,30 @@ export class ProfileFamilyMotherEmployeeController extends Controller { private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother); private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory); + @Get("user") + public async getFamilyMotherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyMother = await this.ProfileFamilyMother.findOne({ + select: [ + "id", + "motherPrefix", + "motherFirstName", + "motherLastName", + "motherCareer", + "motherCitizenId", + "motherLive", + "profileId", + ], + where: { profileEmployeeId: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyMother); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 7613fdc3..d27f2b0e 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -36,6 +36,97 @@ export class ProfileGovernmentEmployeeController extends Controller { private positionRepo = AppDataSource.getRepository(EmployeePosition); private posMasterRepo = AppDataSource.getRepository(EmployeePosMaster); + /** + * + * @summary ข้อมูลราชการ + * + */ + @Get("user") + public async getGovHistoryUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileEmployeeRepo.findOne({ + where: { id: profile.id }, + relations: { + posType: true, + posLevel: true, + }, + }); + const posMaster = await this.posMasterRepo.findOne({ + where: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + current_holderId: profile.id, + }, + order: { createdAt: "DESC" }, + relations: { + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + }, + }); + 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 = [ + posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, + posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, + posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name, + posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name, + posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName, + ]; + const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/"); + let orgShortName = ""; + if (posMaster != null) { + if (posMaster.orgChild1Id === null) { + orgShortName = posMaster.orgRoot?.orgRootShortName; + } else if (posMaster.orgChild2Id === null) { + orgShortName = posMaster.orgChild1?.orgChild1ShortName; + } else if (posMaster.orgChild3Id === null) { + orgShortName = posMaster.orgChild2?.orgChild2ShortName; + } else if (posMaster.orgChild4Id === null) { + orgShortName = posMaster.orgChild3?.orgChild3ShortName; + } else { + orgShortName = posMaster.orgChild4?.orgChild4ShortName; + } + } + const data = { + org: org, //สังกัด + position: record.position, //ตำแหน่ง + posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ + posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), + dateRetireLaw: record.dateRetireLaw ?? null, + govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateAppoint: record.dateAppoint, + dateStart: record.dateStart, + govAgeAbsent: record.govAgeAbsent, + govAgePlus: record.govAgePlus, + reasonSameDate: record.reasonSameDate, + }; + + return new HttpSuccess(data); + } + /** * * @summary ข้อมูลราชการ diff --git a/src/controllers/ProfileHonorEmployeeController.ts b/src/controllers/ProfileHonorEmployeeController.ts index 44157de8..afaf9a00 100644 --- a/src/controllers/ProfileHonorEmployeeController.ts +++ b/src/controllers/ProfileHonorEmployeeController.ts @@ -29,6 +29,18 @@ export class ProfileHonorEmployeeController extends Controller { private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); + @Get("user") + public async getHonorUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.honorRepo.find({ + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileInsigniaEmployeeController.ts b/src/controllers/ProfileInsigniaEmployeeController.ts index 4089c8a1..6de21b7e 100644 --- a/src/controllers/ProfileInsigniaEmployeeController.ts +++ b/src/controllers/ProfileInsigniaEmployeeController.ts @@ -35,6 +35,23 @@ export class ProfileInsigniaEmployeeController extends Controller { private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaMetaRepo = AppDataSource.getRepository(Insignia); + @Get("user") + public async getInsigniaUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.insigniaRepo.find({ + relations: { + insignia: { + insigniaType: true, + }, + }, + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileLeaveEmployeeController.ts b/src/controllers/ProfileLeaveEmployeeController.ts index d62cb018..8f1716c9 100644 --- a/src/controllers/ProfileLeaveEmployeeController.ts +++ b/src/controllers/ProfileLeaveEmployeeController.ts @@ -36,6 +36,19 @@ export class ProfileLeaveEmployeeController extends Controller { private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory); private leaveTypeRepository = AppDataSource.getRepository(LeaveType); + @Get("user") + public async getLeaveUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.leaveRepo.find({ + relations: { leaveType: true }, + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") public async getLeave(@Path() profileId: string) { const record = await this.leaveRepo.find({ diff --git a/src/controllers/ProfileNopaidEmployeeController.ts b/src/controllers/ProfileNopaidEmployeeController.ts index bec7b723..8bda984d 100644 --- a/src/controllers/ProfileNopaidEmployeeController.ts +++ b/src/controllers/ProfileNopaidEmployeeController.ts @@ -33,6 +33,18 @@ export class ProfileNopaidEmployeeController extends Controller { private nopaidRepository = AppDataSource.getRepository(ProfileNopaid); private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory); + @Get("user") + public async getNopaidUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.nopaidRepository.find({ + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getNopaid(@Path() profileId: string) { const lists = await this.nopaidRepository.find({ diff --git a/src/controllers/ProfileOtherEmployeeController.ts b/src/controllers/ProfileOtherEmployeeController.ts index c71ed332..b04addf6 100644 --- a/src/controllers/ProfileOtherEmployeeController.ts +++ b/src/controllers/ProfileOtherEmployeeController.ts @@ -33,6 +33,18 @@ export class ProfileOtherEmployeeController extends Controller { private otherRepository = AppDataSource.getRepository(ProfileOther); private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory); + @Get("user") + public async getOtherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.otherRepository.find({ + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getOther(@Path() profileId: string) { const lists = await this.otherRepository.find({ diff --git a/src/controllers/ProfileSalaryEmployeeController.ts b/src/controllers/ProfileSalaryEmployeeController.ts index 00cd4d54..8f6c7237 100644 --- a/src/controllers/ProfileSalaryEmployeeController.ts +++ b/src/controllers/ProfileSalaryEmployeeController.ts @@ -34,6 +34,19 @@ export class ProfileSalaryEmployeeController extends Controller { private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); + @Get("user") + public async getSalaryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.salaryRepo.find({ + where: { profileEmployeeId: profile.id }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") public async getSalaryEmployee(@Path() profileId: string) { const record = await this.salaryRepo.find({ diff --git a/src/controllers/ProfileTrainingEmployeeController.ts b/src/controllers/ProfileTrainingEmployeeController.ts index 8e8c76d4..e70cc2be 100644 --- a/src/controllers/ProfileTrainingEmployeeController.ts +++ b/src/controllers/ProfileTrainingEmployeeController.ts @@ -33,6 +33,18 @@ export class ProfileTrainingEmployeeController extends Controller { private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); + @Get("user") + public async getTrainingUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.trainingRepo.find({ + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileEmployeeId}") @Example({ status: 200, From 85f8fbb03ab94ca7ec03e99a04cadc6b0f99f2b8 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Fri, 24 May 2024 01:11:47 +0700 Subject: [PATCH 7/7] get profile by token --- src/controllers/ProfileController.ts | 22 +++ src/controllers/ProfileEmployeeController.ts | 131 ++++++++++++------ .../ProfileFamilyFatherController.ts | 2 +- .../ProfileFamilyHistoryEmployeeController.ts | 2 +- .../ProfileGovernmentEmployeeController.ts | 26 ++-- 5 files changed, 124 insertions(+), 59 deletions(-) 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 = [