From 4bfecf789961b7f7ec0037caaac4d926b0ef716b Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Tue, 3 Sep 2024 15:08:29 +0700 Subject: [PATCH] =?UTF-8?q?add=20admin=20path=20=E0=B8=97=E0=B8=B0?= =?UTF-8?q?=E0=B9=80=E0=B8=9A=E0=B8=B5=E0=B8=A2=E0=B8=99=E0=B8=9B=E0=B8=A3?= =?UTF-8?q?=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileAbilityController.ts | 33 ++++++++++++----- .../ProfileAssessmentsController.ts | 36 ++++++++++++++----- .../ProfileCertificateController.ts | 21 ++++++++--- .../ProfileDisciplineController.ts | 15 ++++++-- src/controllers/ProfileDutyController.ts | 13 +++++-- .../ProfileEducationsController.ts | 28 +++++++++++---- src/controllers/ProfileHonorController.ts | 15 ++++++-- src/controllers/ProfileInsigniaController.ts | 25 +++++++++++-- src/controllers/ProfileLeaveController.ts | 14 ++++++-- src/controllers/ProfileOtherController.ts | 21 ++++++++--- src/controllers/ProfileSalaryController.ts | 21 ++++++++--- src/controllers/ProfileTrainingController.ts | 15 ++++++-- 12 files changed, 205 insertions(+), 52 deletions(-) diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index 2f599029..bc6fc5a6 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -61,17 +61,34 @@ export class ProfileAbilityController extends Controller { return new HttpSuccess(getProfileAbilityId); } - @Get("history/{abilityId}") - public async getProfileAbilityHistory( + @Get("admin/history/{abilityId}") + public async getProfileAbilityAdminHistory( @Path() abilityId: string, @Request() req: RequestWithUser, ) { - // const _record = await this.profileAbilityRepo.findOne({ - // where: { id: abilityId }, - // }); - // if (_record) { - // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); - // } + + const _record = await this.profileAbilityRepo.findOne({ + where: { id: abilityId }, + }); + if (_record) { + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); + } + + const record = await this.profileAbilityHistoryRepo.find({ + where: { profileAbilityId: abilityId }, + order: { createdAt: "DESC" }, + }); + + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + + @Get("history/{abilityId}") + public async getProfileAbilityHistory( + @Path() abilityId: string, + ) { const record = await this.profileAbilityHistoryRepo.find({ where: { profileAbilityId: abilityId }, order: { createdAt: "DESC" }, diff --git a/src/controllers/ProfileAssessmentsController.ts b/src/controllers/ProfileAssessmentsController.ts index 314250c7..3e8e084f 100644 --- a/src/controllers/ProfileAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsController.ts @@ -65,10 +65,36 @@ export class ProfileAssessmentsController extends Controller { return new HttpSuccess(getProfileAssessments); } + @Get("admin/history/{assessmentId}") + public async getProfileAssessmentsAdminHistory( + @Path() assessmentId: string, + @Request() req: RequestWithUser, + ) { + const _record = await this.profileAssessmentsRepository.findOne({ + where: { + id: assessmentId, + }, + }); + if (_record) { + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); + } + + const record = await this.profileAssessmentsHistoryRepository.find({ + where: { + profileAssessmentId: assessmentId, + }, + order: { createdAt: "DESC" }, + }); + + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + @Get("history/{assessmentId}") public async getProfileAssessmentsHistory( @Path() assessmentId: string, - @Request() req: RequestWithUser, ) { const record = await this.profileAssessmentsHistoryRepository.find({ where: { @@ -80,14 +106,6 @@ export class ProfileAssessmentsController extends Controller { if (!record) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); } - // const _record = await this.profileAssessmentsRepository.findOne({ - // where: { - // id: assessmentId, - // }, - // }); - // if (_record) { - // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); - // } return new HttpSuccess(record); } diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index cb749795..691f1290 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -55,12 +55,23 @@ export class ProfileCertificateController extends Controller { return new HttpSuccess(record); } + @Get("admin/history/{certificateId}") + public async certificateAdminHistory(@Path() certificateId: string, @Request() req: RequestWithUser) { + const _record = await this.certificateRepo.findOneBy({ id: certificateId }); + if (_record) { + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); + } + const record = await this.certificateHistoryRepo.find({ + where: { + profileCertificateId: certificateId, + }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Get("history/{certificateId}") - public async certificateHistory(@Path() certificateId: string, @Request() req: RequestWithUser) { - // const _record = await this.certificateRepo.findOneBy({ id: certificateId }); - // if (_record) { - // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); - // } + public async certificateHistory(@Path() certificateId: string) { const record = await this.certificateHistoryRepo.find({ where: { profileCertificateId: certificateId, diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index 510b8a69..65687996 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -65,8 +65,8 @@ export class ProfileDisciplineController extends Controller { return new HttpSuccess(lists); } - @Get("history/{disciplineId}") - public async disciplineHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) { + @Get("admin/history/{disciplineId}") + public async disciplineAdminHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) { const _record = await this.disciplineRepository.findOneBy({ id: disciplineId }); if (_record) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); @@ -78,7 +78,16 @@ export class ProfileDisciplineController extends Controller { return new HttpSuccess(record); } - @Post() + @Get("history/{disciplineId}") + public async disciplineHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) { + const record = await this.disciplineHistoryRepository.find({ + where: { profileDisciplineId: disciplineId }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + + @Post() public async newDiscipline( @Request() req: RequestWithUser, @Body() body: CreateProfileDiscipline, diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index 6c909495..16673740 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -51,8 +51,8 @@ export class ProfileDutyController extends Controller { return new HttpSuccess(lists); } - @Get("history/{dutyId}") - public async dutyHistory(@Path() dutyId: string, @Request() req: RequestWithUser) { + @Get("admin/history/{dutyId}") + public async dutyAdminHistory(@Path() dutyId: string, @Request() req: RequestWithUser) { const _record = await this.dutyRepository.findOneBy({ id: dutyId }); if (_record) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); @@ -64,6 +64,15 @@ export class ProfileDutyController extends Controller { return new HttpSuccess(record); } + @Get("history/{dutyId}") + public async dutyHistory(@Path() dutyId: string,) { + const record = await this.dutyHistoryRepository.find({ + where: { profileDutyId: dutyId }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Post() public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileDuty) { if (!body.profileId) { diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index c960dc3d..d1462793 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -63,15 +63,31 @@ export class ProfileEducationsController extends Controller { return new HttpSuccess(getProfileEducation); } - @Get("history/{educationId}") - public async getProfileEducationHistory( + @Get("admin/history/{educationId}") + public async getProfileEducationAdminHistory( @Path() educationId: string, @Request() req: RequestWithUser, ) { - // const _record = await this.profileEducationRepo.findOneBy({ id: educationId }); - // if (_record) { - // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); - // } + const _record = await this.profileEducationRepo.findOneBy({ id: educationId }); + if (_record) { + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); + } + const record = await this.profileEducationHistoryRepo.find({ + where: { + profileEducationId: educationId, + }, + order: { createdAt: "DESC" }, + }); + if (!record) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + } + return new HttpSuccess(record); + } + + @Get("history/{educationId}") + public async getProfileEducationHistory( + @Path() educationId: string, + ) { const record = await this.profileEducationHistoryRepo.find({ where: { profileEducationId: educationId, diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index ac93bc40..8d34c1d0 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -73,8 +73,8 @@ export class ProfileHonorController extends Controller { return new HttpSuccess(record); } - @Get("history/{honorId}") - public async honorHistory(@Path() honorId: string, @Request() req: RequestWithUser) { + @Get("admin/history/{honorId}") + public async honorAdminHistory(@Path() honorId: string, @Request() req: RequestWithUser) { const _record = await this.honorRepo.findOneBy({ id: honorId }); if (_record) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); @@ -88,6 +88,17 @@ export class ProfileHonorController extends Controller { return new HttpSuccess(record); } + @Get("history/{honorId}") + public async honorHistory(@Path() honorId: string, @Request() req: RequestWithUser) { + const record = await this.honorHistoryRepo.find({ + where: { + profileHonorId: honorId, + }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Post() public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileHonor) { if (!body.profileId) { diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index 8d2d34a0..6b6cd43f 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -66,9 +66,12 @@ export class ProfileInsigniaController extends Controller { }); return new HttpSuccess(record); } - - @Get("history/{InsigniaId}") - public async getInsigniaHistory(@Path() InsigniaId: string, @Request() req: RequestWithUser) { + + @Get("admin/history/{InsigniaId}") + public async getInsigniaAdminHistory( + @Path() InsigniaId: string, + @Request() req: RequestWithUser, + ) { const _record = await this.insigniaRepo.findOneBy({ id: InsigniaId }); if (_record) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); @@ -87,6 +90,22 @@ export class ProfileInsigniaController extends Controller { return new HttpSuccess(record); } + @Get("history/{InsigniaId}") + public async getInsigniaHistory(@Path() InsigniaId: string) { + const record = await this.insigniaHistoryRepo.find({ + relations: { + insignia: { + insigniaType: true, + }, + }, + where: { + profileInsigniaId: InsigniaId, + }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Post() public async newInsignia(@Request() req: RequestWithUser, @Body() body: CreateProfileInsignia) { if (!body.profileId) { diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index 843cc39b..c78d331e 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -146,8 +146,8 @@ export class ProfileLeaveController extends Controller { return new HttpSuccess(record); } - @Get("history/{leaveId}") - public async leaveHistory(@Path() leaveId: string, @Request() req: RequestWithUser) { + @Get("admin/history/{leaveId}") + public async leaveAdminHistory(@Path() leaveId: string, @Request() req: RequestWithUser) { const _record = await this.leaveRepo.findOneBy({ id: leaveId }); if (_record) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); @@ -160,6 +160,16 @@ export class ProfileLeaveController extends Controller { return new HttpSuccess(record); } + @Get("history/{leaveId}") + public async leaveHistory(@Path() leaveId: string,) { + const record = await this.leaveHistoryRepo.find({ + relations: { leaveType: true }, + where: { profileLeaveId: leaveId }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Post() public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileLeave) { if (!body.profileId) { diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index e414211f..bd7e38a6 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -52,12 +52,23 @@ export class ProfileOtherController extends Controller { return new HttpSuccess(lists); } + @Get("admin/history/{otherId}") + public async otherAdminHistory(@Path() otherId: string, @Request() req: RequestWithUser) { + + const _record = await this.otherRepository.findOneBy({ id: otherId }); + console.log(">>>>", _record); + if (_record) { + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); + } + const record = await this.otherHistoryRepository.find({ + where: { profileOtherId: otherId }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Get("history/{otherId}") - public async otherHistory(@Path() otherId: string, @Request() req: RequestWithUser) { - // const _record = await this.otherRepository.findOneBy({ id: otherId }); - // if (_record) { - // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); - // } + public async otherHistory(@Path() otherId: string,) { const record = await this.otherHistoryRepository.find({ where: { profileOtherId: otherId }, order: { createdAt: "DESC" }, diff --git a/src/controllers/ProfileSalaryController.ts b/src/controllers/ProfileSalaryController.ts index 5f47f471..8ff9bec6 100644 --- a/src/controllers/ProfileSalaryController.ts +++ b/src/controllers/ProfileSalaryController.ts @@ -63,12 +63,23 @@ export class ProfileSalaryController extends Controller { return new HttpSuccess(record); } + @Get("admin/history/{salaryId}") + public async salaryAdminHistory(@Path() salaryId: string, @Request() req: RequestWithUser) { + const _record = await this.salaryRepo.findOneBy({ id: salaryId }); + if (_record) { + await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); + } + const record = await this.salaryHistoryRepo.find({ + where: { + profileSalaryId: salaryId, + }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Get("history/{salaryId}") - public async salaryHistory(@Path() salaryId: string, @Request() req: RequestWithUser) { - // const _record = await this.salaryRepo.findOneBy({ id: salaryId }); - // if (_record) { - // await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); - // } + public async salaryHistory(@Path() salaryId: string,) { const record = await this.salaryHistoryRepo.find({ where: { profileSalaryId: salaryId, diff --git a/src/controllers/ProfileTrainingController.ts b/src/controllers/ProfileTrainingController.ts index 414c2e56..04f6c937 100644 --- a/src/controllers/ProfileTrainingController.ts +++ b/src/controllers/ProfileTrainingController.ts @@ -55,8 +55,8 @@ export class ProfileTrainingController extends Controller { return new HttpSuccess(record); } - @Get("history/{trainingId}") - public async trainingHistory(@Path() trainingId: string, @Request() req: RequestWithUser) { + @Get("admin/history/{trainingId}") + public async trainingAdminHistory(@Path() trainingId: string, @Request() req: RequestWithUser) { const _record = await this.trainingRepo.findOneBy({ id: trainingId }); if (_record) { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); @@ -70,6 +70,17 @@ export class ProfileTrainingController extends Controller { return new HttpSuccess(record); } + @Get("history/{trainingId}") + public async trainingHistory(@Path() trainingId: string,) { + const record = await this.trainingHistoryRepo.find({ + where: { + profileTrainingId: trainingId, + }, + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(record); + } + @Post() public async newTraining(@Request() req: RequestWithUser, @Body() body: CreateProfileTraining) { if (!body.profileId) {