From 7126d64d7edbdb3e1348dbc0270c277c1e6bc0a9 Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Mon, 27 May 2024 15:17:27 +0700 Subject: [PATCH] add api history/user --- .../ProfileChangeNameController.ts | 31 ++++++++++++ .../ProfileChangeNameEmployeeController.ts | 49 +++++++++++++++---- .../ProfileDisciplineController.ts | 33 +++++++++++++ .../ProfileDisciplineEmployeeController.ts | 33 +++++++++++++ src/controllers/ProfileDutyController.ts | 34 +++++++++++++ .../ProfileDutyEmployeeController.ts | 36 +++++++++++++- 6 files changed, 206 insertions(+), 10 deletions(-) diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index 8ddf8a86..fc22d7c7 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -70,6 +70,37 @@ 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 244a0fd1..eb3b7deb 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -72,6 +72,37 @@ 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, @@ -146,7 +177,7 @@ export class ProfileChangeNameEmployeeController extends Controller { profile.lastName = body.lastName ?? profile.lastName; profile.prefix = body.prefix ?? profile.prefix; await this.profileEmployeeRepo.save(profile); - + return new HttpSuccess(data.id); } @@ -174,17 +205,17 @@ export class ProfileChangeNameEmployeeController extends Controller { ]); const chkLastRecord = await this.changeNameRepository.findOne({ - where:{ - profileEmployeeId: record.profileEmployeeId + where: { + profileEmployeeId: record.profileEmployeeId, }, - order:{ - createdAt: "DESC" - } - }) + order: { + createdAt: "DESC", + }, + }); if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - + const profile = await this.profileEmployeeRepo.findOneBy({ id: record.profileEmployeeId }); - + if (profile && chkLastRecord.id === record.id) { profile.firstName = body.firstName ?? profile.firstName; profile.lastName = body.lastName ?? profile.lastName; diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index 47cd35ed..843fba02 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -75,6 +75,39 @@ 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 4819c9f3..86303782 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -90,6 +90,39 @@ 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 bbea6c69..59e4fa17 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -82,6 +82,40 @@ 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 0a435c92..87091f98 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -22,7 +22,7 @@ import { ProfileEmployee } from "../entities/ProfileEmployee"; import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; @Route("api/v1/org/profile-employee/duty") -@Tags("ProfileDuty") +@Tags("ProfileEmployeeDuty") @Security("bearerAuth") export class ProfileDutyEmployeeController extends Controller { private profileRepository = AppDataSource.getRepository(ProfileEmployee); @@ -67,6 +67,40 @@ 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({