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,