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/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..497d45b7 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: 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/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/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/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/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index c21d8db0..10185798 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("user") + 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/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/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/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/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/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/ProfileController.ts b/src/controllers/ProfileController.ts index 7518fc04..9867c9b0 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") @@ -136,6 +137,16 @@ 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}/`; @@ -144,21 +155,34 @@ 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 : null, + 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.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}`, }; @@ -524,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 รายละเอียดรายการทะเบียนประวัติ * @@ -1061,6 +1107,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, 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/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/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/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/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/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/ProfileEmployeeController.ts b/src/controllers/ProfileEmployeeController.ts index aaf2fefe..89dcb41f 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") @@ -126,6 +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 _root = root == null || root == undefined ? "" : `${root.orgRootName}`; let _child1 = child1 == null || child1 == undefined ? "" : `${child1.orgChild1Name}/`; let _child2 = child2 == null || child2 == undefined ? "" : `${child2.orgChild2Name}/`; @@ -134,21 +145,34 @@ 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, + 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.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}`, }; @@ -343,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 รายละเอียดรายการทะเบียนประวัติ * diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index 8e23a6a3..a3b76cfa 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: { profileId: 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/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/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index fd20707b..919190af 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: { profileId: 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/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/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 6d696560..7928ef92 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: { profileId: profile.id }, + }); + const children = await this.childrenRepo.find({ + order: { createdAt: "ASC" }, + where: { profileId: profile.id }, + }); + return new HttpSuccess( + family.length > 0 + ? { + ...family[0], + children, + } + : null, + ); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyHistoryEmployeeController.ts b/src/controllers/ProfileFamilyHistoryEmployeeController.ts index ce34730d..0315886e 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: { profileEmployeeId: 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/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index 122fe977..cad827d2 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: { profileId: 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/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/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/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 7613fdc3..6cd224b3 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/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/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/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index a83e97a0..184d3307 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: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @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/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 6510dff1..60e866b2 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: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @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/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index d2a531fd..06b163d8 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: { profileId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, 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/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/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/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/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/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, 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,