diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index f0ad9a54..a49e9130 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -79,29 +79,6 @@ export class ProfileAbilityController extends Controller { return new HttpSuccess(getProfileAbilityId); } - /** - * - * @summary ประวัติแก้ไขความสามารถ by keycloak - * - */ - @Get("history/user") - public async getProfileAbilityHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.profileAbilityHistoryRepo.find({ - where: { - histories: { - profileId: profile.id, - }, - }, - }); - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - return new HttpSuccess(record); - } @Get("history/{abilityId}") @Example({ diff --git a/src/controllers/ProfileAbilityEmployeeController.ts b/src/controllers/ProfileAbilityEmployeeController.ts index 6df1d56a..10e67463 100644 --- a/src/controllers/ProfileAbilityEmployeeController.ts +++ b/src/controllers/ProfileAbilityEmployeeController.ts @@ -81,29 +81,6 @@ export class ProfileAbilityEmployeeController extends Controller { return new HttpSuccess(getProfileAbilityId); } - /** - * - * @summary ประวัติแก้ไขความสามารถ by keycloak - * - */ - @Get("history/user") - public async getProfileAbilityHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.profileAbilityHistoryRepo.find({ - where: { - histories: { - profileEmployeeId: profile.id, - }, - }, - }); - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - return new HttpSuccess(record); - } @Get("history/{abilityId}") @Example({ diff --git a/src/controllers/ProfileAssessmentsController.ts b/src/controllers/ProfileAssessmentsController.ts index a53eb43c..5b008045 100644 --- a/src/controllers/ProfileAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsController.ts @@ -87,35 +87,6 @@ export class ProfileAssessmentsController extends Controller { return new HttpSuccess(getProfileAssessments); } - /** - * - * @summary ประวัติแก้ไขการประเมิน by keycloak - * - */ - @Get("history/user") - public async getProfileAssessmentsHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.profileAssessmentsHistoryRepository.find({ - relations: { - histories: true, - }, - where: { - histories: { - profileId: profile.id, - }, - }, - }); - - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - - return new HttpSuccess(record); - } - @Get("history/{assessmentId}") @Example({ status: 200, diff --git a/src/controllers/ProfileAssessmentsEmployeeController.ts b/src/controllers/ProfileAssessmentsEmployeeController.ts index 7d39e5f5..7813e928 100644 --- a/src/controllers/ProfileAssessmentsEmployeeController.ts +++ b/src/controllers/ProfileAssessmentsEmployeeController.ts @@ -89,35 +89,6 @@ export class ProfileAssessmentsEmployeeController extends Controller { return new HttpSuccess(getProfileAssessments); } - /** - * - * @summary ประวัติแก้ไขการประเมิน by keycloak - * - */ - @Get("history/user") - public async getProfileAssessmentsHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.profileAssessmentsHistoryRepository.find({ - relations: { - histories: true, - }, - where: { - histories: { - profileEmployeeId: profile.id, - }, - }, - }); - - if (!record) { - throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - } - - return new HttpSuccess(record); - } - @Get("history/{assessmentId}") @Example({ status: 200, diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index 54517353..b8abf0bb 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -72,27 +72,7 @@ export class ProfileCertificateController extends Controller { return new HttpSuccess(record); } - /** - * - * @summary ประวัติแก้ไขใบรับรอง by keycloak - * - */ - @Get("history/user") - public async certificateHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.certificateHistoryRepo.find({ - where: { - histories: { - profileId: profile.id, - }, - }, - }); - return new HttpSuccess(record); - } - + @Get("history/{certificateId}") @Example({ status: 200, diff --git a/src/controllers/ProfileCertificateEmployeeController.ts b/src/controllers/ProfileCertificateEmployeeController.ts index 764ea77d..5fbcfc55 100644 --- a/src/controllers/ProfileCertificateEmployeeController.ts +++ b/src/controllers/ProfileCertificateEmployeeController.ts @@ -72,27 +72,6 @@ export class ProfileCertificateEmployeeController extends Controller { return new HttpSuccess(record); } - /** - * - * @summary ประวัติแก้ไขใบรับรอง by keycloak - * - */ - @Get("history/user") - public async certificateHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.certificateHistoryRepo.find({ - where: { - histories: { - profileEmployeeId: profile.id, - }, - }, - }); - return new HttpSuccess(record); - } - @Get("history/{certificateId}") @Example({ status: 200, diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index fc22d7c7..8ddf8a86 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -70,37 +70,6 @@ export class ProfileChangeNameController extends Controller { return new HttpSuccess(lists); } - /** - * - * @summary ประวัติแก้ไขชื่อ by keycloak - * - */ - @Get("history/user") - public async changeNameHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.changeNameHistoryRepository.find({ - where: { - histories: { - profileId: profile.id, - }, - }, - select: [ - "id", - "prefix", - "firstName", - "lastName", - "status", - "lastUpdateFullName", - "lastUpdatedAt", - ], - order: { createdAt: "DESC" }, - }); - return new HttpSuccess(record); - } - @Get("history/{changeNameId}") @Example({ status: 200, diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index eb3b7deb..5d653f59 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -72,37 +72,6 @@ export class ProfileChangeNameEmployeeController extends Controller { return new HttpSuccess(lists); } - /** - * - * @summary ประวัติแก้ไขชื่อ by keycloak - * - */ - @Get("history/user") - public async changeNameHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.changeNameHistoryRepository.find({ - where: { - histories: { - profileEmployeeId: profile.id, - }, - }, - select: [ - "id", - "prefix", - "firstName", - "lastName", - "status", - "lastUpdateFullName", - "lastUpdatedAt", - ], - order: { createdAt: "DESC" }, - }); - return new HttpSuccess(record); - } - @Get("history/{changeNameId}") @Example({ status: 200, diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index 843fba02..47cd35ed 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -75,39 +75,6 @@ export class ProfileDisciplineController extends Controller { return new HttpSuccess(lists); } - /** - * - * @summary ประวัติแก้ไขข้อมูลวินัย by keycloak - * - */ - @Get("history/user") - public async disciplineHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.disciplineHistoryRepository.find({ - where: { - histories: { - profileId: profile.id, - }, - }, - select: [ - "id", - "date", - "level", - "detail", - "unStigma", - "refCommandNo", - "refCommandDate", - "lastUpdateFullName", - "lastUpdatedAt", - ], - order: { createdAt: "DESC" }, - }); - return new HttpSuccess(record); - } - @Get("history/{disciplineId}") @Example({ status: 200, diff --git a/src/controllers/ProfileDisciplineEmployeeController.ts b/src/controllers/ProfileDisciplineEmployeeController.ts index 86303782..4819c9f3 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -90,39 +90,6 @@ export class ProfileDisciplineEmployeeController extends Controller { return new HttpSuccess(lists); } - /** - * - * @summary ประวัติแก้ไขข้อมูลวินัย by keycloak - * - */ - @Get("history/user") - public async disciplineHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - const record = await this.disciplineHistoryRepository.find({ - where: { - histories: { - profileEmployeeId: profile.id, - }, - }, - select: [ - "id", - "date", - "level", - "detail", - "unStigma", - "refCommandNo", - "refCommandDate", - "lastUpdateFullName", - "lastUpdatedAt", - ], - order: { createdAt: "DESC" }, - }); - return new HttpSuccess(record); - } - @Get("history/{disciplineId}") public async disciplineHistory(@Path() disciplineId: string) { const record = await this.disciplineHistoryRepository.find({ diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index 59e4fa17..bbea6c69 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -82,40 +82,6 @@ export class ProfileDutyController extends Controller { return new HttpSuccess(lists); } - /** - * - * @summary ประวัติแก้ไขตำแหน่งหน้าที่ by keycloak - * - */ - @Get("history/user") - public async dutyHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - - const record = await this.dutyHistoryRepository.find({ - where: { - histories: { - profileId: profile.id, - }, - }, - select: [ - "id", - "dateStart", - "dateEnd", - "reference", - "detail", - "refCommandNo", - "refCommandDate", - "lastUpdateFullName", - "lastUpdatedAt", - ], - order: { createdAt: "DESC" }, - }); - return new HttpSuccess(record); - } - @Get("history/{dutyId}") @Example({ status: 200, diff --git a/src/controllers/ProfileDutyEmployeeController.ts b/src/controllers/ProfileDutyEmployeeController.ts index 87091f98..8d039092 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -67,40 +67,6 @@ export class ProfileDutyEmployeeController extends Controller { return new HttpSuccess(lists); } - /** - * - * @summary ประวัติแก้ไขตำแหน่งหน้าที่ by keycloak - * - */ - @Get("history/user") - public async dutyHistoryUser(@Request() request: RequestWithUser) { - const profile = await this.profileRepository.findOneBy({ keycloak: request.user.sub }); - if (!profile) { - throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); - } - - const record = await this.dutyHistoryRepository.find({ - where: { - histories: { - profileEmployeeId: profile.id, - }, - }, - select: [ - "id", - "dateStart", - "dateEnd", - "reference", - "detail", - "refCommandNo", - "refCommandDate", - "lastUpdateFullName", - "lastUpdatedAt", - ], - order: { createdAt: "DESC" }, - }); - return new HttpSuccess(record); - } - @Get("history/{dutyId}") public async dutyHistory(@Path() dutyId: string) { const record = await this.dutyHistoryRepository.find({ diff --git a/src/controllers/ProfileFamilyCoupleController.ts b/src/controllers/ProfileFamilyCoupleController.ts index a3b76cfa..8d3cda07 100644 --- a/src/controllers/ProfileFamilyCoupleController.ts +++ b/src/controllers/ProfileFamilyCoupleController.ts @@ -104,6 +104,51 @@ export class ProfileFamilyCoupleController extends Controller { return new HttpSuccess(familyCouple); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyCoupleHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const familyCouple = await this.ProfileFamilyCouple.find({ + relations: ["histories"], + order: { lastUpdatedAt: "DESC" }, + where: { + profileId: profile.id, + }, + }); + + 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: profile.id, + })); + + return new HttpSuccess(mapData); + } + @Get("history/{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyCoupleEmployeeController.ts b/src/controllers/ProfileFamilyCoupleEmployeeController.ts index 4ccca644..61c46dc6 100644 --- a/src/controllers/ProfileFamilyCoupleEmployeeController.ts +++ b/src/controllers/ProfileFamilyCoupleEmployeeController.ts @@ -74,16 +74,24 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { }) public async getFamilyCouple(@Path() profileEmployeeId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } - }) + where: { id: profileEmployeeId }, + }); 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", "profileEmployeeId", + "id", + "couplePrefix", + "coupleFirstName", + "coupleLastName", + "coupleLastNameOld", + "coupleCareer", + "coupleCitizenId", + "coupleLive", + "relationship", + "profileEmployeeId", ], where: { profileEmployeeId }, order: { lastUpdatedAt: "DESC" }, @@ -92,6 +100,51 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { return new HttpSuccess(familyCouple); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyCoupleHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const familyCouple = await this.ProfileFamilyCouple.find({ + relations: ["histories"], + order: { lastUpdatedAt: "DESC" }, + where: { + profileEmployeeId: profile.id, + }, + }); + + 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, + profileEmployeeId: profile.id, + })); + + return new HttpSuccess(mapData); + } + @Get("history/{profileEmployeeId}") @Example({ status: 200, @@ -115,13 +168,13 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { relationship: "string", profileFamilyCoupleId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyCoupleHistory(@Path() profileEmployeeId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } - }) + where: { id: profileEmployeeId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -129,28 +182,30 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { const familyCouple = await this.ProfileFamilyCouple.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileEmployeeId: profileEmployeeId}, + where: { profileEmployeeId: profileEmployeeId }, }); - 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, - profileEmployeeId: profileEmployeeId, - })); + 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, + profileEmployeeId: profileEmployeeId, + })); return new HttpSuccess(mapData); } @@ -168,7 +223,7 @@ export class ProfileFamilyCoupleEmployeeController 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; @@ -176,7 +231,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { await this.ProfileFamilyCouple.save(familyCouple); if (familyCouple) { - profile.relationship = familyCouple.relationship //update profileEmployee.relationship + profile.relationship = familyCouple.relationship; //update profileEmployee.relationship const history: ProfileFamilyCoupleHistory = Object.assign(new ProfileFamilyCoupleHistory(), { profileFamilyCoupleId: familyCouple.id, couplePrefix: familyCouple.couplePrefix, @@ -194,7 +249,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { }); await Promise.all([ this.profileRepo.save(profile), - this.ProfileFamilyCoupleHistory.save(history) + this.ProfileFamilyCoupleHistory.save(history), ]); } return new HttpSuccess(familyCouple.id); @@ -206,26 +261,28 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { @Body() body: UpdateProfileFamilyCouple, @Path() profileEmployeeId: string, ) { - const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileEmployeeId: profileEmployeeId }); + const familyCouple = await this.ProfileFamilyCouple.findOneBy({ + profileEmployeeId: profileEmployeeId, + }); if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); 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), @@ -234,5 +291,4 @@ export class ProfileFamilyCoupleEmployeeController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileFamilyFatherController.ts b/src/controllers/ProfileFamilyFatherController.ts index 919190af..56171677 100644 --- a/src/controllers/ProfileFamilyFatherController.ts +++ b/src/controllers/ProfileFamilyFatherController.ts @@ -98,6 +98,47 @@ export class ProfileFamilyFatherController extends Controller { return new HttpSuccess(familyFather); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyFatherHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const familyFather = await this.ProfileFamilyFather.find({ + relations: ["histories"], + order: { lastUpdatedAt: "DESC" }, + where: { profileId: profile.id }, + }); + + 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: profile.id, + })); + + return new HttpSuccess(mapData); + } + @Get("history/{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyFatherEmployeeController.ts b/src/controllers/ProfileFamilyFatherEmployeeController.ts index 07bdbb39..9135c51d 100644 --- a/src/controllers/ProfileFamilyFatherEmployeeController.ts +++ b/src/controllers/ProfileFamilyFatherEmployeeController.ts @@ -18,7 +18,11 @@ import HttpStatus from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { RequestWithUser } from "../middlewares/user"; import { ProfileEmployee } from "../entities/ProfileEmployee"; -import { ProfileFamilyFather, CreateProfileEmployeeFamilyFather, UpdateProfileFamilyFather } from "../entities/ProfileFamilyFather"; +import { + ProfileFamilyFather, + CreateProfileEmployeeFamilyFather, + UpdateProfileFamilyFather, +} from "../entities/ProfileFamilyFather"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import Extension from "../interfaces/extension"; @Route("api/v1/org/profile-employee/family/father") @@ -70,16 +74,22 @@ export class ProfileFamilyFatherEmployeeController extends Controller { }) public async getFamilyFather(@Path() profileEmployeeId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } - }) + where: { id: profileEmployeeId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyFather = await this.ProfileFamilyFather.findOne({ select: [ - "id", "fatherPrefix", "fatherFirstName", "fatherLastName", - "fatherCareer", "fatherCitizenId", "fatherLive", "profileEmployeeId", + "id", + "fatherPrefix", + "fatherFirstName", + "fatherLastName", + "fatherCareer", + "fatherCitizenId", + "fatherLive", + "profileEmployeeId", ], where: { profileEmployeeId }, order: { lastUpdatedAt: "DESC" }, @@ -88,6 +98,47 @@ export class ProfileFamilyFatherEmployeeController extends Controller { return new HttpSuccess(familyFather); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyFatherHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const familyFather = await this.ProfileFamilyFather.find({ + relations: ["histories"], + order: { lastUpdatedAt: "DESC" }, + where: { profileEmployeeId: profile.id }, + }); + + 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, + profileEmployeeId: profile.id, + })); + + return new HttpSuccess(mapData); + } + @Get("history/{profileEmployeeId}") @Example({ status: 200, @@ -109,13 +160,13 @@ export class ProfileFamilyFatherEmployeeController extends Controller { fatherLive: true, profileFamilyFatherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyFatherHistory(@Path() profileEmployeeId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } - }) + where: { id: profileEmployeeId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -123,26 +174,28 @@ export class ProfileFamilyFatherEmployeeController extends Controller { const familyFather = await this.ProfileFamilyFather.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileEmployeeId: profileEmployeeId}, + where: { profileEmployeeId: profileEmployeeId }, }); - 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, - profileEmployeeId: profileEmployeeId, - })); + 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, + profileEmployeeId: profileEmployeeId, + })); return new HttpSuccess(mapData); } @@ -160,7 +213,7 @@ export class ProfileFamilyFatherEmployeeController 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; @@ -192,24 +245,26 @@ export class ProfileFamilyFatherEmployeeController extends Controller { @Body() body: UpdateProfileFamilyFather, @Path() profileEmployeeId: string, ) { - const familyFather = await this.ProfileFamilyFather.findOneBy({ profileEmployeeId: profileEmployeeId }); + const familyFather = await this.ProfileFamilyFather.findOneBy({ + profileEmployeeId: profileEmployeeId, + }); if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); 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; - 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), @@ -218,5 +273,4 @@ export class ProfileFamilyFatherEmployeeController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileFamilyHistoryController.ts b/src/controllers/ProfileFamilyHistoryController.ts index 7928ef92..39f45bcf 100644 --- a/src/controllers/ProfileFamilyHistoryController.ts +++ b/src/controllers/ProfileFamilyHistoryController.ts @@ -134,6 +134,38 @@ export class ProfileFamilyHistoryController extends Controller { ); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyHistoryUser(@Request() request: RequestWithUser) { + 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({ + order: { lastUpdatedAt: "DESC" }, + where: { + profileId: profile.id + }, + }); + + family.shift(); + + const record = await Promise.all( + family.map(async (v) => ({ + ...v, + children: await this.childrenHistoryRepo.find({ + order: { createdAt: "ASC" }, + }), + })), + ); + + return new HttpSuccess(record); + } + @Get("history/{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyHistoryEmployeeController.ts b/src/controllers/ProfileFamilyHistoryEmployeeController.ts index 0315886e..34647a43 100644 --- a/src/controllers/ProfileFamilyHistoryEmployeeController.ts +++ b/src/controllers/ProfileFamilyHistoryEmployeeController.ts @@ -134,6 +134,38 @@ export class ProfileFamilyHistoryEmployeeController extends Controller { ); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyHistoryUser(@Request() request: RequestWithUser) { + 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({ + order: { lastUpdatedAt: "DESC" }, + where: { + profileEmployeeId: profile.id, + }, + }); + + family.shift(); + + const record = await Promise.all( + family.map(async (v) => ({ + ...v, + children: await this.childrenHistoryRepo.find({ + order: { createdAt: "ASC" }, + }), + })), + ); + + return new HttpSuccess(record); + } + @Get("history/{profileEmployeeId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyMotherController.ts b/src/controllers/ProfileFamilyMotherController.ts index cad827d2..55acab88 100644 --- a/src/controllers/ProfileFamilyMotherController.ts +++ b/src/controllers/ProfileFamilyMotherController.ts @@ -98,6 +98,47 @@ export class ProfileFamilyMotherController extends Controller { return new HttpSuccess(familyMother); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyMotherHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const familyMother = await this.ProfileFamilyMother.find({ + relations: ["histories"], + order: { lastUpdatedAt: "DESC" }, + where: { profileId: profile.id }, + }); + + 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: profile.id, + })); + + return new HttpSuccess(mapData); + } + @Get("history/{profileId}") @Example({ status: 200, diff --git a/src/controllers/ProfileFamilyMotherEmployeeController.ts b/src/controllers/ProfileFamilyMotherEmployeeController.ts index 4afcc1e7..4b6325fb 100644 --- a/src/controllers/ProfileFamilyMotherEmployeeController.ts +++ b/src/controllers/ProfileFamilyMotherEmployeeController.ts @@ -70,16 +70,22 @@ export class ProfileFamilyMotherEmployeeController extends Controller { }) public async getFamilyMother(@Path() profileEmployeeId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } - }) + where: { id: profileEmployeeId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } const familyMother = await this.ProfileFamilyMother.findOne({ select: [ - "id", "motherPrefix", "motherFirstName", "motherLastName", - "motherCareer", "motherCitizenId", "motherLive", "profileEmployeeId", + "id", + "motherPrefix", + "motherFirstName", + "motherLastName", + "motherCareer", + "motherCitizenId", + "motherLive", + "profileEmployeeId", ], where: { profileEmployeeId }, order: { lastUpdatedAt: "DESC" }, @@ -88,6 +94,47 @@ export class ProfileFamilyMotherEmployeeController extends Controller { return new HttpSuccess(familyMother); } + /** + * + * @summary ประวัติแก้ไขครอบครัว by keycloak + * + */ + @Get("history/user") + public async familyMotherHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + + const familyMother = await this.ProfileFamilyMother.find({ + relations: ["histories"], + order: { lastUpdatedAt: "DESC" }, + where: { profileEmployeeId: profile.id }, + }); + + 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, + profileEmployeeId: profile.id, + })); + + return new HttpSuccess(mapData); + } + @Get("history/{profileEmployeeId}") @Example({ status: 200, @@ -109,13 +156,13 @@ export class ProfileFamilyMotherEmployeeController extends Controller { motherLive: true, profileFamilyMotherId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", - } + }, ], }) public async familyMotherHistory(@Path() profileEmployeeId: string) { const profile = await this.profileRepo.findOne({ - where: { id: profileEmployeeId } - }) + where: { id: profileEmployeeId }, + }); if (!profile) { throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); } @@ -123,26 +170,28 @@ export class ProfileFamilyMotherEmployeeController extends Controller { const familyMother = await this.ProfileFamilyMother.find({ relations: ["histories"], order: { lastUpdatedAt: "DESC" }, - where: { profileEmployeeId: profileEmployeeId}, + where: { profileEmployeeId: profileEmployeeId }, }); - 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, - profileEmployeeId: profileEmployeeId, - })); + 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, + profileEmployeeId: profileEmployeeId, + })); return new HttpSuccess(mapData); } @@ -160,7 +209,7 @@ export class ProfileFamilyMotherEmployeeController 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; @@ -192,24 +241,26 @@ export class ProfileFamilyMotherEmployeeController extends Controller { @Body() body: UpdateProfileFamilyMother, @Path() profileEmployeeId: string, ) { - const familyMother = await this.ProfileFamilyMother.findOneBy({ profileEmployeeId: profileEmployeeId }); + const familyMother = await this.ProfileFamilyMother.findOneBy({ + profileEmployeeId: profileEmployeeId, + }); if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); 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), @@ -218,5 +269,4 @@ export class ProfileFamilyMotherEmployeeController extends Controller { return new HttpSuccess(); } - } diff --git a/src/controllers/ProfileGovernmentController.ts b/src/controllers/ProfileGovernmentController.ts index 68d09879..6b1d1508 100644 --- a/src/controllers/ProfileGovernmentController.ts +++ b/src/controllers/ProfileGovernmentController.ts @@ -218,6 +218,24 @@ export class ProfileGovernmentHistoryController extends Controller { return new HttpSuccess(data); } + /** + * + * @summary ประวัติข้อมูลราชการ by keycloak + * + */ + @Get("history/user") + public async govHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.govRepo.find({ + order: { lastUpdatedAt: "DESC" }, + where: { profileId: profile.id }, + }); + return new HttpSuccess(record); + } + /** * * @summary ประวัติข้อมูลราชการ diff --git a/src/controllers/ProfileGovernmentEmployeeController.ts b/src/controllers/ProfileGovernmentEmployeeController.ts index 6cd224b3..73c40045 100644 --- a/src/controllers/ProfileGovernmentEmployeeController.ts +++ b/src/controllers/ProfileGovernmentEmployeeController.ts @@ -215,6 +215,24 @@ export class ProfileGovernmentEmployeeController extends Controller { return new HttpSuccess(data); } + /** + * + * @summary ประวัติข้อมูลราชการ by keycloak + * + */ + @Get("history/user") + public async govHistoryUser(@Request() request: RequestWithUser) { + const profile = await this.profileEmployeeRepo.findOneBy({ keycloak: request.user.sub }); + if (!profile) { + throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); + } + const record = await this.govRepo.find({ + order: { lastUpdatedAt: "DESC" }, + where: { profileEmployeeId: profile.id }, + }); + return new HttpSuccess(record); + } + /** * * @summary ประวัติข้อมูลราชการ