From ff0be7af48362309b81dd35819a02e5a774ed7c2 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 23 May 2024 16:44:37 +0700 Subject: [PATCH] =?UTF-8?q?get=20=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1?= =?UTF-8?q?=E0=B8=B9=E0=B8=A5=20by=20keycloak?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileAbilityController.ts | 15 ++ .../ProfileAbilityEmployeeController.ts | 17 ++- src/controllers/ProfileAddressController.ts | 28 ++++ .../ProfileAssessmentsController.ts | 15 ++ .../ProfileCertificateController.ts | 12 ++ .../ProfileChangeNameController.ts | 30 ++-- src/controllers/ProfileChildrenController.ts | 23 +++- .../ProfileDisciplineController.ts | 23 ++++ src/controllers/ProfileDutyController.ts | 21 +++ .../ProfileEducationsController.ts | 15 ++ .../ProfileFamilyCoupleController.ts | 129 ++++++++++++------ .../ProfileFamilyFatherController.ts | 112 +++++++++------ .../ProfileFamilyHistoryController.ts | 25 ++++ .../ProfileFamilyMotherController.ts | 113 +++++++++------ .../ProfileGovernmentController.ts | 101 ++++++++++++++ src/controllers/ProfileHonorController.ts | 12 ++ src/controllers/ProfileInsigniaController.ts | 17 +++ src/controllers/ProfileLeaveController.ts | 13 ++ src/controllers/ProfileNopaidController.ts | 12 ++ src/controllers/ProfileOtherController.ts | 12 ++ src/controllers/ProfileSalaryController.ts | 13 ++ src/controllers/ProfileTrainingController.ts | 12 ++ 22 files changed, 633 insertions(+), 137 deletions(-) diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index 161f8ae8..facb4d29 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -33,6 +33,21 @@ export class ProfileAbilityController extends Controller { private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility); private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory); + @Get("user") + public async detailProfileAbilityUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAbilityId = await this.profileAbilityRepo.find({ + where: { profileId: profile.id }, + }); + if (!getProfileAbilityId) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAbilityId); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileAbilityEmployeeController.ts b/src/controllers/ProfileAbilityEmployeeController.ts index 5826dfc4..47c56d92 100644 --- a/src/controllers/ProfileAbilityEmployeeController.ts +++ b/src/controllers/ProfileAbilityEmployeeController.ts @@ -35,6 +35,21 @@ export class ProfileAbilityEmployeeController extends Controller { private profileAbilityRepo = AppDataSource.getRepository(ProfileAbility); private profileAbilityHistoryRepo = AppDataSource.getRepository(ProfileAbilityHistory); + @Get("user") + public async detailProfileAbilityUser(@Request() request: { user: Record }) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAbilityId = await this.profileAbilityRepo.find({ + where: { profileEmployeeId: profile.id }, + }); + if (!getProfileAbilityId) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAbilityId); + } + @Get("{profileEmployeeId}") @Example({ status: 200, @@ -181,7 +196,7 @@ export class ProfileAbilityEmployeeController extends Controller { if (result.affected == undefined || result.affected <= 0) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - + return new HttpSuccess(); } } diff --git a/src/controllers/ProfileAddressController.ts b/src/controllers/ProfileAddressController.ts index 9e283744..e2edab5f 100644 --- a/src/controllers/ProfileAddressController.ts +++ b/src/controllers/ProfileAddressController.ts @@ -34,6 +34,34 @@ export class ProfileAddressController extends Controller { private profileRepo = AppDataSource.getRepository(Profile); private profileAddressHistoryRepo = AppDataSource.getRepository(ProfileAddressHistory); + @Get("user") + public async detailProfileAddressUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAddress = await this.profileRepo.findOne({ + where: { id: request.user.sub }, + select: [ + "id", + "registrationAddress", + "registrationProvinceId", + "registrationDistrictId", + "registrationSubDistrictId", + "registrationZipCode", + "currentAddress", + "currentProvinceId", + "currentDistrictId", + "currentSubDistrictId", + "currentZipCode", + ], + }); + if (!getProfileAddress) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAddress); + } + /** * * @summary ข้อมูลที่อยู่ diff --git a/src/controllers/ProfileAssessmentsController.ts b/src/controllers/ProfileAssessmentsController.ts index e261083c..5b008045 100644 --- a/src/controllers/ProfileAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsController.ts @@ -39,6 +39,21 @@ export class ProfileAssessmentsController extends Controller { private profileAssessmentsHistoryRepository = AppDataSource.getRepository(ProfileAssessmentHistory); + @Get("user") + public async detailProfileAssessmentsUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileAssessments = await this.profileAssessmentsRepository.find({ + where: { profileId: profile.id }, + }); + if (!getProfileAssessments) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileAssessments); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index c21d8db0..56f08974 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -33,6 +33,18 @@ export class ProfileCertificateController extends Controller { private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); + @Get("{profileId}") + public async getCertificateUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.certificateRepo.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index 0d3d0740..8ddf8a86 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -33,6 +33,20 @@ export class ProfileChangeNameController extends Controller { private changeNameRepository = AppDataSource.getRepository(ProfileChangeName); private changeNameHistoryRepository = AppDataSource.getRepository(ProfileChangeNameHistory); + @Get("user") + public async getChangeNameUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.changeNameRepository.find({ + where: { profileId: profile.id }, + select: ["id", "prefix", "firstName", "lastName", "status"], + order: { createdAt: "ASC" }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, @@ -158,17 +172,17 @@ export class ProfileChangeNameController extends Controller { ]); const chkLastRecord = await this.changeNameRepository.findOne({ - where:{ - profileId: record.profileId + where: { + profileId: record.profileId, }, - order:{ - createdAt: "DESC" - } - }) + order: { + createdAt: "DESC", + }, + }); if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + const profile = await this.profileRepository.findOneBy({ id: record.profileId }); - + if (profile && chkLastRecord.id === record.id) { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; diff --git a/src/controllers/ProfileChildrenController.ts b/src/controllers/ProfileChildrenController.ts index 36ff9839..f2b4f202 100644 --- a/src/controllers/ProfileChildrenController.ts +++ b/src/controllers/ProfileChildrenController.ts @@ -33,6 +33,18 @@ export class ProfileChildrenController extends Controller { private childrenRepository = AppDataSource.getRepository(ProfileChildren); private childrenHistoryRepository = AppDataSource.getRepository(ProfileChildrenHistory); + @Get("user") + public async getChildrenUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.childrenRepository.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getChildren(@Path() profileId: string) { const lists = await this.childrenRepository.find({ @@ -67,9 +79,9 @@ export class ProfileChildrenController extends Controller { }; Object.assign(data, { ...body, ...meta }); - data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId)); + data.childrenCitizenId = Extension.CheckCitizen(String(data.childrenCitizenId)); await this.childrenRepository.save(data); - if(data){ + if (data) { const history: ProfileChildrenHistory = Object.assign(new ProfileChildrenHistory(), { profileChildrenId: data.id, childrenCareer: data.childrenCareer, @@ -102,16 +114,15 @@ export class ProfileChildrenController extends Controller { Object.assign(record, body); record.lastUpdateUserId = req.user.sub; record.lastUpdateFullName = req.user.name; - record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId)); + record.childrenCitizenId = Extension.CheckCitizen(String(record.childrenCitizenId)); history.profileChildrenId = record.id; history.childrenCareer = record.childrenCareer; history.childrenFirstName = record.childrenFirstName; history.childrenLastName = record.childrenLastName; - history.childrenPrefix = record.childrenPrefix; + history.childrenPrefix = record.childrenPrefix; history.childrenLive = record.childrenLive; history.childrenCitizenId = record.childrenCitizenId; - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.lastUpdateUserId = req.user.sub), (history.lastUpdateFullName = req.user.name); await Promise.all([ this.childrenRepository.save(record), this.childrenHistoryRepository.save(history), diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index cb374bb9..47cd35ed 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -33,6 +33,29 @@ export class ProfileDisciplineController extends Controller { private disciplineRepository = AppDataSource.getRepository(ProfileDiscipline); private disciplineHistoryRepository = AppDataSource.getRepository(ProfileDisciplineHistory); + @Get("user") + public async getDisciplineUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.disciplineRepository.find({ + where: { profileId: profile.id }, + select: [ + "id", + "date", + "level", + "detail", + "unStigma", + "refCommandNo", + "refCommandDate", + "lastUpdateFullName", + "lastUpdatedAt", + ], + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") public async getDiscipline(@Path() profileId: string) { const lists = await this.disciplineRepository.find({ diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index b88754c6..bbea6c69 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -29,6 +29,27 @@ export class ProfileDutyController extends Controller { private dutyRepository = AppDataSource.getRepository(ProfileDuty); private dutyHistoryRepository = AppDataSource.getRepository(ProfileDutyHistory); + @Get("user") + public async getDutyUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.dutyRepository.find({ + where: { profileId: profile.id }, + select: [ + "id", + "dateStart", + "dateEnd", + "reference", + "detail", + "refCommandNo", + "refCommandDate", + ], + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index dffba92d..358cf6fa 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -39,6 +39,21 @@ export class ProfileEducationsController extends Controller { private profileEducationRepo = AppDataSource.getRepository(ProfileEducation); private profileEducationHistoryRepo = AppDataSource.getRepository(ProfileEducationHistory); + @Get("user") + public async detailProfileEducationUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const getProfileEducation = await this.profileEducationRepo.find({ + where: { profileId: profile.id }, + }); + if (!getProfileEducation) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(getProfileEducation); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index 8e23a6a3..039118fe 100644 --- a/src/controllers/ProfileFamilyCoupleController.ts +++ b/src/controllers/ProfileFamilyCoupleController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; -import { ProfileFamilyCouple, CreateProfileFamilyCouple, UpdateProfileFamilyCouple } from "../entities/ProfileFamilyCouple"; +import { + ProfileFamilyCouple, + CreateProfileFamilyCouple, + UpdateProfileFamilyCouple, +} from "../entities/ProfileFamilyCouple"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile/family/couple") @@ -29,6 +33,32 @@ export class ProfileFamilyCoupleController extends Controller { private ProfileFamilyCouple = AppDataSource.getRepository(ProfileFamilyCouple); private ProfileFamilyCoupleHistory = AppDataSource.getRepository(ProfileFamilyCoupleHistory); + @Get("user") + public async getFamilyCoupleUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyCouple = await this.ProfileFamilyCouple.findOne({ + select: [ + "id", + "couplePrefix", + "coupleFirstName", + "coupleLastName", + "coupleLastNameOld", + "coupleCareer", + "coupleCitizenId", + "coupleLive", + "relationship", + "profileId", + ], + where: { id: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyCouple); + } + @Get("{profileId}") @Example({ status: 200, @@ -48,16 +78,24 @@ export class ProfileFamilyCoupleController extends Controller { }) public async getFamilyCouple(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyCouple = await this.ProfileFamilyCouple.findOne({ select: [ - "id", "couplePrefix", "coupleFirstName", "coupleLastName", "coupleLastNameOld", - "coupleCareer", "coupleCitizenId", "coupleLive", "relationship", "profileId", + "id", + "couplePrefix", + "coupleFirstName", + "coupleLastName", + "coupleLastNameOld", + "coupleCareer", + "coupleCitizenId", + "coupleLive", + "relationship", + "profileId", ], where: { profileId }, order: { lastUpdatedAt: "DESC" }, @@ -89,13 +127,13 @@ export class ProfileFamilyCoupleController extends Controller { relationship: "string", profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyCoupleHistory(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -103,28 +141,30 @@ export class ProfileFamilyCoupleController extends Controller { const familyCouple = await this.ProfileFamilyCouple.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileId: profileId}, + where: { profileId: profileId }, }); - const mapData = familyCouple.flatMap((x) => x.histories).map((y) => ({ - id: y.id, - createdAt: y.createdAt, - createdUserId: y.createdUserId, - lastUpdatedAt: y.lastUpdatedAt, - lastUpdateUserId: y.lastUpdateUserId, - createdFullName: y.createdFullName, - lastUpdateFullName: y.lastUpdateFullName, - couplePrefix: y.couplePrefix, - coupleFirstName: y.coupleFirstName, - coupleLastName: y.coupleLastName, - coupleLastNameOld: y.coupleLastNameOld, - coupleCareer: y.coupleCareer, - coupleCitizenId: y.coupleCitizenId, - coupleLive: y.coupleLive, - relationship: y.relationship, - profileFamilyCoupleId: y.profileFamilyCoupleId, - profileId: profileId, - })); + const mapData = familyCouple + .flatMap((x) => x.histories) + .map((y) => ({ + id: y.id, + createdAt: y.createdAt, + createdUserId: y.createdUserId, + lastUpdatedAt: y.lastUpdatedAt, + lastUpdateUserId: y.lastUpdateUserId, + createdFullName: y.createdFullName, + lastUpdateFullName: y.lastUpdateFullName, + couplePrefix: y.couplePrefix, + coupleFirstName: y.coupleFirstName, + coupleLastName: y.coupleLastName, + coupleLastNameOld: y.coupleLastNameOld, + coupleCareer: y.coupleCareer, + coupleCitizenId: y.coupleCitizenId, + coupleLive: y.coupleLive, + relationship: y.relationship, + profileFamilyCoupleId: y.profileFamilyCoupleId, + profileId: profileId, + })); return new HttpSuccess(mapData); } @@ -142,7 +182,7 @@ export class ProfileFamilyCoupleController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); + familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); familyCouple.createdUserId = req.user.sub; familyCouple.createdFullName = req.user.name; familyCouple.lastUpdateUserId = req.user.sub; @@ -150,7 +190,7 @@ export class ProfileFamilyCoupleController extends Controller { await this.ProfileFamilyCouple.save(familyCouple); if (familyCouple) { - profile.relationship = familyCouple.relationship //update profile.relationship + profile.relationship = familyCouple.relationship; //update profile.relationship const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), { profileFamilyCoupleId: familyCouple.id, couplePrefix: familyCouple.couplePrefix, @@ -168,7 +208,7 @@ export class ProfileFamilyCoupleController extends Controller { }); await Promise.all([ this.profileRepo.save(profile), - this.ProfileFamilyCoupleHistory.save(history) + this.ProfileFamilyCoupleHistory.save(history), ]); } return new HttpSuccess(familyCouple.id); @@ -186,20 +226,20 @@ export class ProfileFamilyCoupleController extends Controller { const history = new ProfileFamilyCoupleHistory(); Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(familyCouple, body); - familyCouple.lastUpdateUserId = req.user.sub, - familyCouple.lastUpdateFullName = req.user.name; - familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); + (familyCouple.lastUpdateUserId = req.user.sub), + (familyCouple.lastUpdateFullName = req.user.name); + familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); history.profileFamilyCoupleId = familyCouple.id; - history.couplePrefix = familyCouple.couplePrefix, - history.coupleFirstName = familyCouple.coupleFirstName, - history.coupleLastName = familyCouple.coupleLastName, - history.coupleLastNameOld = familyCouple.coupleLastNameOld, - history.coupleCareer = familyCouple.coupleCareer, - history.coupleCitizenId = familyCouple.coupleCitizenId, - history.coupleLive = familyCouple.coupleLive, - history.relationship = familyCouple.relationship, - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.couplePrefix = familyCouple.couplePrefix), + (history.coupleFirstName = familyCouple.coupleFirstName), + (history.coupleLastName = familyCouple.coupleLastName), + (history.coupleLastNameOld = familyCouple.coupleLastNameOld), + (history.coupleCareer = familyCouple.coupleCareer), + (history.coupleCitizenId = familyCouple.coupleCitizenId), + (history.coupleLive = familyCouple.coupleLive), + (history.relationship = familyCouple.relationship), + (history.lastUpdateUserId = req.user.sub), + (history.lastUpdateFullName = req.user.name); await Promise.all([ this.ProfileFamilyCouple.save(familyCouple), @@ -208,5 +248,4 @@ export class ProfileFamilyCoupleController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index fd20707b..9d9dc0f0 100644 --- a/src/controllers/ProfileFamilyFatherController.ts +++ b/src/controllers/ProfileFamilyFatherController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; -import { ProfileFamilyFather, CreateProfileFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather"; +import { + ProfileFamilyFather, + CreateProfileFamilyFather, + UpdateProfileFamilyFather, +} from "../entities/ProfileFamilyFather"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile/family/father") @@ -29,6 +33,30 @@ export class ProfileFamilyFatherController extends Controller { private ProfileFamilyFather = AppDataSource.getRepository(ProfileFamilyFather); private ProfileFamilyFatherHistory = AppDataSource.getRepository(ProfileFamilyFatherHistory); + @Get("user") + public async getFamilyFatherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyFather = await this.ProfileFamilyFather.findOne({ + select: [ + "id", + "fatherPrefix", + "fatherFirstName", + "fatherLastName", + "fatherCareer", + "fatherCitizenId", + "fatherLive", + "profileId", + ], + where: { id: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyFather); + } + @Get("{profileId}") @Example({ status: 200, @@ -46,16 +74,22 @@ export class ProfileFamilyFatherController extends Controller { }) public async getFamilyFather(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyFather = await this.ProfileFamilyFather.findOne({ select: [ - "id", "fatherPrefix", "fatherFirstName", "fatherLastName", - "fatherCareer", "fatherCitizenId", "fatherLive", "profileId", + "id", + "fatherPrefix", + "fatherFirstName", + "fatherLastName", + "fatherCareer", + "fatherCitizenId", + "fatherLive", + "profileId", ], where: { profileId }, order: { lastUpdatedAt: "DESC" }, @@ -85,13 +119,13 @@ export class ProfileFamilyFatherController extends Controller { fatherLive: true, profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyFatherHistory(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -99,26 +133,28 @@ export class ProfileFamilyFatherController extends Controller { const familyFather = await this.ProfileFamilyFather.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileId: profileId}, + where: { profileId: profileId }, }); - const mapData = familyFather.flatMap((x) => x.histories).map((y) => ({ - id: y.id, - createdAt: y.createdAt, - createdUserId: y.createdUserId, - lastUpdatedAt: y.lastUpdatedAt, - lastUpdateUserId: y.lastUpdateUserId, - createdFullName: y.createdFullName, - lastUpdateFullName: y.lastUpdateFullName, - fatherPrefix: y.fatherPrefix, - fatherFirstName: y.fatherFirstName, - fatherLastName: y.fatherLastName, - fatherCareer: y.fatherCareer, - fatherCitizenId: y.fatherCitizenId, - fatherLive: y.fatherLive, - profileFamilyFatherId: y.profileFamilyFatherId, - profileId: profileId, - })); + const mapData = familyFather + .flatMap((x) => x.histories) + .map((y) => ({ + id: y.id, + createdAt: y.createdAt, + createdUserId: y.createdUserId, + lastUpdatedAt: y.lastUpdatedAt, + lastUpdateUserId: y.lastUpdateUserId, + createdFullName: y.createdFullName, + lastUpdateFullName: y.lastUpdateFullName, + fatherPrefix: y.fatherPrefix, + fatherFirstName: y.fatherFirstName, + fatherLastName: y.fatherLastName, + fatherCareer: y.fatherCareer, + fatherCitizenId: y.fatherCitizenId, + fatherLive: y.fatherLive, + profileFamilyFatherId: y.profileFamilyFatherId, + profileId: profileId, + })); return new HttpSuccess(mapData); } @@ -136,7 +172,7 @@ export class ProfileFamilyFatherController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); + familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.createdUserId = req.user.sub; familyFather.createdFullName = req.user.name; familyFather.lastUpdateUserId = req.user.sub; @@ -174,18 +210,18 @@ export class ProfileFamilyFatherController extends Controller { const history = new ProfileFamilyFatherHistory(); Object.assign(history, { ...familyFather, id: undefined }); Object.assign(familyFather, body); - familyFather.lastUpdateUserId = req.user.sub, - familyFather.lastUpdateFullName = req.user.name; - familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); + (familyFather.lastUpdateUserId = req.user.sub), + (familyFather.lastUpdateFullName = req.user.name); + familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); history.profileFamilyFatherId = familyFather.id; //profileFamilyFatherId - history.fatherPrefix = familyFather.fatherPrefix, - history.fatherFirstName = familyFather.fatherFirstName, - history.fatherLastName = familyFather.fatherLastName, - history.fatherCareer = familyFather.fatherCareer, - history.fatherCitizenId = familyFather.fatherCitizenId, - history.fatherLive = familyFather.fatherLive, - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.fatherPrefix = familyFather.fatherPrefix), + (history.fatherFirstName = familyFather.fatherFirstName), + (history.fatherLastName = familyFather.fatherLastName), + (history.fatherCareer = familyFather.fatherCareer), + (history.fatherCitizenId = familyFather.fatherCitizenId), + (history.fatherLive = familyFather.fatherLive), + (history.lastUpdateUserId = req.user.sub), + (history.lastUpdateFullName = req.user.name); await Promise.all([ this.ProfileFamilyFather.save(familyFather), diff --git a/src/controllers/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 6d696560..1ea363ea 100644 --- a/src/controllers/ProfileFamilyHistoryController.ts +++ b/src/controllers/ProfileFamilyHistoryController.ts @@ -36,6 +36,31 @@ export class ProfileFamilyHistoryController extends Controller { private childrenRepo = AppDataSource.getRepository(ProfileChildren); private childrenHistoryRepo = AppDataSource.getRepository(ProfileChildrenHistory); + @Get("user") + public async getFamilyHistoryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const family = await this.familyHistoryRepo.find({ + take: 1, + order: { lastUpdatedAt: "DESC" }, + where: { id: profile.id }, + }); + const children = await this.childrenRepo.find({ + order: { createdAt: "ASC" }, + where: { id: profile.id }, + }); + return new HttpSuccess( + family.length > 0 + ? { + ...family[0], + children, + } + : null, + ); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index 122fe977..879b7795 100644 --- a/src/controllers/ProfileFamilyMotherController.ts +++ b/src/controllers/ProfileFamilyMotherController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { Profile } from "../entities/Profile"; -import { ProfileFamilyMother, CreateProfileFamilyMother, UpdateProfileFamilyMother } from "../entities/ProfileFamilyMother"; +import { + ProfileFamilyMother, + CreateProfileFamilyMother, + UpdateProfileFamilyMother, +} from "../entities/ProfileFamilyMother"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile/family/mother") @@ -29,6 +33,30 @@ export class ProfileFamilyMotherController extends Controller { private ProfileFamilyMother = AppDataSource.getRepository(ProfileFamilyMother); private ProfileFamilyMotherHistory = AppDataSource.getRepository(ProfileFamilyMotherHistory); + @Get("user") + public async getFamilyMotherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const familyMother = await this.ProfileFamilyMother.findOne({ + select: [ + "id", + "motherPrefix", + "motherFirstName", + "motherLastName", + "motherCareer", + "motherCitizenId", + "motherLive", + "profileId", + ], + where: { id: profile.id }, + order: { lastUpdatedAt: "DESC" }, + }); + + return new HttpSuccess(familyMother); + } + @Get("{profileId}") @Example({ status: 200, @@ -46,16 +74,22 @@ export class ProfileFamilyMotherController extends Controller { }) public async getFamilyMother(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyMother = await this.ProfileFamilyMother.findOne({ select: [ - "id", "motherPrefix", "motherFirstName", "motherLastName", - "motherCareer", "motherCitizenId", "motherLive", "profileId", + "id", + "motherPrefix", + "motherFirstName", + "motherLastName", + "motherCareer", + "motherCitizenId", + "motherLive", + "profileId", ], where: { profileId }, order: { lastUpdatedAt: "DESC" }, @@ -85,13 +119,13 @@ export class ProfileFamilyMotherController extends Controller { motherLive: true, profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyMotherHistory(@Path() profileId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileId } - }) + where: { id: profileId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -99,26 +133,28 @@ export class ProfileFamilyMotherController extends Controller { const familyMother = await this.ProfileFamilyMother.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileId: profileId}, + where: { profileId: profileId }, }); - const mapData = familyMother.flatMap((x) => x.histories).map((y) => ({ - id: y.id, - createdAt: y.createdAt, - createdUserId: y.createdUserId, - lastUpdatedAt: y.lastUpdatedAt, - lastUpdateUserId: y.lastUpdateUserId, - createdFullName: y.createdFullName, - lastUpdateFullName: y.lastUpdateFullName, - motherPrefix: y.motherPrefix, - motherFirstName: y.motherFirstName, - motherLastName: y.motherLastName, - motherCareer: y.motherCareer, - motherCitizenId: y.motherCitizenId, - motherLive: y.motherLive, - profileFamilyMotherId: y.profileFamilyMotherId, - profileId: profileId, - })); + const mapData = familyMother + .flatMap((x) => x.histories) + .map((y) => ({ + id: y.id, + createdAt: y.createdAt, + createdUserId: y.createdUserId, + lastUpdatedAt: y.lastUpdatedAt, + lastUpdateUserId: y.lastUpdateUserId, + createdFullName: y.createdFullName, + lastUpdateFullName: y.lastUpdateFullName, + motherPrefix: y.motherPrefix, + motherFirstName: y.motherFirstName, + motherLastName: y.motherLastName, + motherCareer: y.motherCareer, + motherCitizenId: y.motherCitizenId, + motherLive: y.motherLive, + profileFamilyMotherId: y.profileFamilyMotherId, + profileId: profileId, + })); return new HttpSuccess(mapData); } @@ -136,7 +172,7 @@ export class ProfileFamilyMotherController extends Controller { if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } - familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); + familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.createdUserId = req.user.sub; familyMother.createdFullName = req.user.name; familyMother.lastUpdateUserId = req.user.sub; @@ -174,18 +210,18 @@ export class ProfileFamilyMotherController extends Controller { const history = new ProfileFamilyMotherHistory(); Object.assign(history, { ...familyMother, id: undefined }); Object.assign(familyMother, body); - familyMother.lastUpdateUserId = req.user.sub, - familyMother.lastUpdateFullName = req.user.name; - familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); + (familyMother.lastUpdateUserId = req.user.sub), + (familyMother.lastUpdateFullName = req.user.name); + familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); history.profileFamilyMotherId = familyMother.id; - history.motherPrefix = familyMother.motherPrefix, - history.motherFirstName = familyMother.motherFirstName, - history.motherLastName = familyMother.motherLastName, - history.motherCareer = familyMother.motherCareer, - history.motherCitizenId = familyMother.motherCitizenId, - history.motherLive = familyMother.motherLive, - history.lastUpdateUserId = req.user.sub, - history.lastUpdateFullName = req.user.name; + (history.motherPrefix = familyMother.motherPrefix), + (history.motherFirstName = familyMother.motherFirstName), + (history.motherLastName = familyMother.motherLastName), + (history.motherCareer = familyMother.motherCareer), + (history.motherCitizenId = familyMother.motherCitizenId), + (history.motherLive = familyMother.motherLive), + (history.lastUpdateUserId = req.user.sub), + (history.lastUpdateFullName = req.user.name); await Promise.all([ this.ProfileFamilyMother.save(familyMother), @@ -194,5 +230,4 @@ export class ProfileFamilyMotherController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 02a5a128..68d09879 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -19,6 +19,107 @@ export class ProfileGovernmentHistoryController extends Controller { private positionRepo = AppDataSource.getRepository(Position); private posMasterRepo = AppDataSource.getRepository(PosMaster); + /** + * + * @summary ข้อมูลราชการ + * + */ + @Get("user") + public async getGovHistoryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.profileRepo.findOne({ + where: { id: profile.id }, + relations: { + posType: true, + posLevel: true, + }, + }); + const posMaster = await this.posMasterRepo.findOne({ + where: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + current_holderId: profile.id, + }, + order: { createdAt: "DESC" }, + relations: { + orgRoot: true, + orgChild1: true, + orgChild2: true, + orgChild3: true, + orgChild4: true, + }, + }); + const position = await this.positionRepo.findOne({ + where: { + positionIsSelected: true, + posMaster: { + orgRevision: { + orgRevisionIsCurrent: true, + orgRevisionIsDraft: false, + }, + current_holderId: profile.id, + }, + }, + order: { createdAt: "DESC" }, + relations: { + posExecutive: true, + }, + }); + + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const fullNameParts = [ + posMaster == null || posMaster.orgChild4 == null ? null : posMaster.orgChild4.orgChild4Name, + posMaster == null || posMaster.orgChild3 == null ? null : posMaster.orgChild3.orgChild3Name, + posMaster == null || posMaster.orgChild2 == null ? null : posMaster.orgChild2.orgChild2Name, + posMaster == null || posMaster.orgChild1 == null ? null : posMaster.orgChild1.orgChild1Name, + posMaster == null || posMaster.orgRoot == null ? null : posMaster.orgRoot.orgRootName, + ]; + const org = fullNameParts.filter((part) => part !== undefined && part !== null).join("/"); + let orgShortName = ""; + if (posMaster != null) { + if (posMaster.orgChild1Id === null) { + orgShortName = posMaster.orgRoot?.orgRootShortName; + } else if (posMaster.orgChild2Id === null) { + orgShortName = posMaster.orgChild1?.orgChild1ShortName; + } else if (posMaster.orgChild3Id === null) { + orgShortName = posMaster.orgChild2?.orgChild2ShortName; + } else if (posMaster.orgChild4Id === null) { + orgShortName = posMaster.orgChild3?.orgChild3ShortName; + } else { + orgShortName = posMaster.orgChild4?.orgChild4ShortName; + } + } + const data = { + org: org, //สังกัด + positionField: position == null ? null : position.positionField, //สายงาน + position: record.position, //ตำแหน่ง + posLevel: record.posLevel == null ? null : record.posLevel.posLevelName, //ระดับ + posMasterNo: posMaster == null ? null : `${orgShortName} ${posMaster.posMasterNo}`, //เลขที่ตำแหน่ง + posType: record.posType == null ? null : record.posType.posTypeName, //ประเภท + posExecutive: + position == null || position.posExecutive == null + ? null + : position.posExecutive.posExecutiveName, //ตำแหน่งทางการบริหาร + positionArea: position == null ? null : position.positionArea, //ด้าน/สาขา + positionExecutiveField: position == null ? null : position.positionExecutiveField, //ด้านทางการบริหาร + dateLeave: record.birthDate == null ? null : calculateRetireDate(record.birthDate), + dateRetireLaw: record.dateRetireLaw ?? null, + govAge: record.dateStart == null ? null : calculateAge(record.dateStart), + dateAppoint: record.dateAppoint, + dateStart: record.dateStart, + govAgeAbsent: record.govAgeAbsent, + govAgePlus: record.govAgePlus, + reasonSameDate: record.reasonSameDate, + }; + + return new HttpSuccess(data); + } + /** * * @summary ข้อมูลราชการ diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index 9a03daa3..a66fa2d6 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -29,6 +29,18 @@ export class ProfileHonorController extends Controller { private honorRepo = AppDataSource.getRepository(ProfileHonor); private honorHistoryRepo = AppDataSource.getRepository(ProfileHonorHistory); + @Get("user") + public async getHonorUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.honorRepo.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index a83e97a0..1f1d9ec3 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -35,6 +35,23 @@ export class ProfileInsigniaController extends Controller { private insigniaHistoryRepo = AppDataSource.getRepository(ProfileInsigniaHistory); private insigniaMetaRepo = AppDataSource.getRepository(Insignia); + @Get("user") + public async getInsigniaUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.insigniaRepo.find({ + relations: { + insignia: { + insigniaType: true, + }, + }, + where: { id: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 6510dff1..07289054 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -36,6 +36,19 @@ export class ProfileLeaveController extends Controller { private leaveHistoryRepo = AppDataSource.getRepository(ProfileLeaveHistory); private leaveTypeRepository = AppDataSource.getRepository(LeaveType); + @Get("user") + public async getLeaveUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.leaveRepo.find({ + relations: { leaveType: true }, + where: { id: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index d2a531fd..d79a0f0b 100644 --- a/src/controllers/ProfileNopaidController.ts +++ b/src/controllers/ProfileNopaidController.ts @@ -29,6 +29,18 @@ export class ProfileNopaidController extends Controller { private nopaidRepository = AppDataSource.getRepository(ProfileNopaid); private nopaidHistoryRepository = AppDataSource.getRepository(ProfileNopaidHistory); + @Get("user") + public async getNopaidUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.nopaidRepository.find({ + where: { id: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index 1a4eeeed..5737a12d 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -29,6 +29,18 @@ export class ProfileOtherController extends Controller { private otherRepository = AppDataSource.getRepository(ProfileOther); private otherHistoryRepository = AppDataSource.getRepository(ProfileOtherHistory); + @Get("user") + public async getOtherUser(@Request() request: { user: Record }) { + const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const lists = await this.otherRepository.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(lists); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index ebc6c27a..cf565bcc 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -30,6 +30,19 @@ export class ProfileSalaryController extends Controller { private salaryRepo = AppDataSource.getRepository(ProfileSalary); private salaryHistoryRepo = AppDataSource.getRepository(ProfileSalaryHistory); + @Get("user") + public async getSalaryUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.salaryRepo.find({ + where: { profileId: profile.id }, + order: { order: "ASC" }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index 00585eca..4c9b20a7 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -33,6 +33,18 @@ export class ProfileTrainingController extends Controller { private trainingRepo = AppDataSource.getRepository(ProfileTraining); private trainingHistoryRepo = AppDataSource.getRepository(ProfileTrainingHistory); + @Get("user") + public async getTrainingUser(@Request() request: { user: Record }) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.trainingRepo.find({ + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + @Get("{profileId}") @Example({ status: 200,