From 9382482f06368ebd3136c5387581c59c766b86f8 Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 16 Feb 2026 10:30:15 +0700 Subject: [PATCH] api soft delete --- src/controllers/ProfileAbilityController.ts | 39 ++++++++++++++++++ .../ProfileAbilityEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileAbilityEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileAssessmentsController.ts | 39 ++++++++++++++++++ .../ProfileAssessmentsEmployeeController.ts | 39 ++++++++++++++++++ ...rofileAssessmentsEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileAssistanceController.ts | 39 ++++++++++++++++++ .../ProfileAssistanceEmployeeController.ts | 40 +++++++++++++++++++ ...ProfileAssistanceEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileCertificateController.ts | 39 ++++++++++++++++++ .../ProfileCertificateEmployeeController.ts | 39 ++++++++++++++++++ ...rofileCertificateEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileChangeNameController.ts | 39 ++++++++++++++++++ .../ProfileChangeNameEmployeeController.ts | 39 ++++++++++++++++++ ...ProfileChangeNameEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileChildrenController.ts | 39 ++++++++++++++++++ .../ProfileChildrenEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileChildrenEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileDisciplineController.ts | 39 ++++++++++++++++++ .../ProfileDisciplineEmployeeController.ts | 39 ++++++++++++++++++ ...ProfileDisciplineEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileDutyController.ts | 39 ++++++++++++++++++ .../ProfileDutyEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileDutyEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileEducationsController.ts | 39 ++++++++++++++++++ .../ProfileEducationsEmployeeController.ts | 39 ++++++++++++++++++ ...ProfileEducationsEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileHonorController.ts | 39 ++++++++++++++++++ .../ProfileHonorEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileHonorEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileInsigniaController.ts | 39 ++++++++++++++++++ .../ProfileInsigniaEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileInsigniaEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileLeaveController.ts | 39 ++++++++++++++++++ .../ProfileLeaveEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileLeaveEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileNopaidController.ts | 39 ++++++++++++++++++ .../ProfileNopaidEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileNopaidEmployeeTempController.ts | 39 ++++++++++++++++++ src/controllers/ProfileOtherController.ts | 39 ++++++++++++++++++ .../ProfileOtherEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileOtherEmployeeTempController.ts | 39 ++++++++++++++++++ .../ProfileTrainingEmployeeController.ts | 39 ++++++++++++++++++ .../ProfileTrainingEmployeeTempController.ts | 39 ++++++++++++++++++ 44 files changed, 1717 insertions(+) diff --git a/src/controllers/ProfileAbilityController.ts b/src/controllers/ProfileAbilityController.ts index c8012057..3faa7c08 100644 --- a/src/controllers/ProfileAbilityController.ts +++ b/src/controllers/ProfileAbilityController.ts @@ -174,6 +174,45 @@ export class ProfileAbilityController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลความสามารถพิเศษ + * @summary API ลบข้อมูลความสามารถพิเศษ + * @param abilityId คีย์ความสามารถพิเศษ + */ + @Patch("update-delete/{abilityId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() abilityId: string, + ) { + const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileAbilityHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAbilityId = abilityId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAbilityRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAbilityHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{abilityId}") public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) { const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); diff --git a/src/controllers/ProfileAbilityEmployeeController.ts b/src/controllers/ProfileAbilityEmployeeController.ts index d7ba3ae9..096b77d8 100644 --- a/src/controllers/ProfileAbilityEmployeeController.ts +++ b/src/controllers/ProfileAbilityEmployeeController.ts @@ -183,6 +183,45 @@ export class ProfileAbilityEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลความสามารถพิเศษ + * @summary API ลบข้อมูลความสามารถพิเศษ + * @param abilityId คีย์ความสามารถพิเศษ + */ + @Patch("update-delete/{abilityId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() abilityId: string, + ) { + const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileAbilityHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAbilityId = abilityId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAbilityRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAbilityHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{abilityId}") public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) { const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); diff --git a/src/controllers/ProfileAbilityEmployeeTempController.ts b/src/controllers/ProfileAbilityEmployeeTempController.ts index 624c8ded..3a4e356a 100644 --- a/src/controllers/ProfileAbilityEmployeeTempController.ts +++ b/src/controllers/ProfileAbilityEmployeeTempController.ts @@ -173,6 +173,45 @@ export class ProfileAbilityEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลความสามารถพิเศษ + * @summary API ลบข้อมูลความสามารถพิเศษ + * @param abilityId คีย์ความสามารถพิเศษ + */ + @Patch("update-delete/{abilityId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() abilityId: string, + ) { + const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileAbilityHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAbilityId = abilityId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAbilityRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAbilityHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{abilityId}") public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) { const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); diff --git a/src/controllers/ProfileAssessmentsController.ts b/src/controllers/ProfileAssessmentsController.ts index 53906cb2..1a7bc662 100644 --- a/src/controllers/ProfileAssessmentsController.ts +++ b/src/controllers/ProfileAssessmentsController.ts @@ -186,6 +186,45 @@ export class ProfileAssessmentsController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลผลการประเมินการปฏิบัติราชการ + * @summary API ลบข้อมูลผลการประเมินการปฏิบัติราชการ + * @param assessmentId คีย์ผลการประเมินการปฏิบัติราชการ + */ + @Patch("update-delete/{assessmentId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() assessmentId: string, + ) { + const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileAssessmentHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAssessmentId = assessmentId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAssessmentsRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAssessmentsHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{assessmentId}") public async deleteProfileAssessment( @Path() assessmentId: string, diff --git a/src/controllers/ProfileAssessmentsEmployeeController.ts b/src/controllers/ProfileAssessmentsEmployeeController.ts index 0f7f3d81..04587937 100644 --- a/src/controllers/ProfileAssessmentsEmployeeController.ts +++ b/src/controllers/ProfileAssessmentsEmployeeController.ts @@ -193,6 +193,45 @@ export class ProfileAssessmentsEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลผลการประเมินการปฏิบัติราชการ + * @summary API ลบข้อมูลผลการประเมินการปฏิบัติราชการ + * @param assessmentId คีย์ผลการประเมินการปฏิบัติราชการ + */ + @Patch("update-delete/{assessmentId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() assessmentId: string, + ) { + const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileAssessmentHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAssessmentId = assessmentId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAssessmentsRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAssessmentsHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{assessmentId}") public async deleteProfileAssessment( @Path() assessmentId: string, diff --git a/src/controllers/ProfileAssessmentsEmployeeTempController.ts b/src/controllers/ProfileAssessmentsEmployeeTempController.ts index b6bc45e6..77689709 100644 --- a/src/controllers/ProfileAssessmentsEmployeeTempController.ts +++ b/src/controllers/ProfileAssessmentsEmployeeTempController.ts @@ -181,6 +181,45 @@ export class ProfileAssessmentsEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลผลการประเมินการปฏิบัติราชการ + * @summary API ลบข้อมูลผลการประเมินการปฏิบัติราชการ + * @param assessmentId คีย์ผลการประเมินการปฏิบัติราชการ + */ + @Patch("update-delete/{assessmentId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() assessmentId: string, + ) { + const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileAssessmentHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAssessmentId = assessmentId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAssessmentsRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAssessmentsHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{assessmentId}") public async deleteProfileAssessment( @Path() assessmentId: string, diff --git a/src/controllers/ProfileAssistanceController.ts b/src/controllers/ProfileAssistanceController.ts index 3690f5e6..a2ec5643 100644 --- a/src/controllers/ProfileAssistanceController.ts +++ b/src/controllers/ProfileAssistanceController.ts @@ -175,6 +175,45 @@ export class ProfileAssistanceController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลช่วยราชการ + * @summary API ลบข้อมูลช่วยราชการ + * @param assistanceId คีย์ช่วยราชการ + */ + @Patch("update-delete/{assistanceId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() assistanceId: string, + ) { + const record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileAssistanceHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAssistanceId = assistanceId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAssistanceRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAssistanceHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{assistanceId}") public async deleteProfileAssistance( @Path() assistanceId: string, diff --git a/src/controllers/ProfileAssistanceEmployeeController.ts b/src/controllers/ProfileAssistanceEmployeeController.ts index 88617322..065b5142 100644 --- a/src/controllers/ProfileAssistanceEmployeeController.ts +++ b/src/controllers/ProfileAssistanceEmployeeController.ts @@ -183,6 +183,46 @@ export class ProfileAssistanceEmployeeController extends Controller { return new HttpSuccess(); } + + /** + * API ลบข้อมูลช่วยราชการ + * @summary API ลบข้อมูลช่วยราชการ + * @param assistanceId คีย์ช่วยราชการ + */ + @Patch("update-delete/{assistanceId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() assistanceId: string, + ) { + const record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileAssistanceHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAssistanceId = assistanceId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAssistanceRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAssistanceHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{assistanceId}") public async deleteProfileAssistance( @Path() assistanceId: string, diff --git a/src/controllers/ProfileAssistanceEmployeeTempController.ts b/src/controllers/ProfileAssistanceEmployeeTempController.ts index da37c3a5..26d88476 100644 --- a/src/controllers/ProfileAssistanceEmployeeTempController.ts +++ b/src/controllers/ProfileAssistanceEmployeeTempController.ts @@ -173,6 +173,45 @@ export class ProfileAssistanceEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลช่วยราชการ + * @summary API ลบข้อมูลช่วยราชการ + * @param assistanceId คีย์ช่วยราชการ + */ + @Patch("update-delete/{assistanceId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() assistanceId: string, + ) { + const record = await this.profileAssistanceRepo.findOneBy({ id: assistanceId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileAssistanceHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileAssistanceId = assistanceId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileAssistanceRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileAssistanceHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{assistanceId}") public async deleteProfileAssistance( @Path() assistanceId: string, diff --git a/src/controllers/ProfileCertificateController.ts b/src/controllers/ProfileCertificateController.ts index 5cbc019a..9d29dc10 100644 --- a/src/controllers/ProfileCertificateController.ts +++ b/src/controllers/ProfileCertificateController.ts @@ -166,6 +166,45 @@ export class ProfileCertificateController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลใบอนุญาตประกอบวิชาชีพ + * @summary API ลบข้อมูลใบอนุญาตประกอบวิชาชีพ + * @param certificateId คีย์ใบอนุญาตประกอบวิชาชีพ + */ + @Patch("update-delete/{certificateId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() certificateId: string, + ) { + const record = await this.certificateRepo.findOneBy({ id: certificateId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileCertificateHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileCertificateId = certificateId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.certificateRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.certificateHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{certificateId}") public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) { const _record = await this.certificateRepo.findOneBy({ id: certificateId }); diff --git a/src/controllers/ProfileCertificateEmployeeController.ts b/src/controllers/ProfileCertificateEmployeeController.ts index 6bb4c1df..74796f9e 100644 --- a/src/controllers/ProfileCertificateEmployeeController.ts +++ b/src/controllers/ProfileCertificateEmployeeController.ts @@ -174,6 +174,45 @@ export class ProfileCertificateEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลใบอนุญาตประกอบวิชาชีพ + * @summary API ลบข้อมูลใบอนุญาตประกอบวิชาชีพ + * @param certificateId คีย์ใบอนุญาตประกอบวิชาชีพ + */ + @Patch("update-delete/{certificateId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() certificateId: string, + ) { + const record = await this.certificateRepo.findOneBy({ id: certificateId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileCertificateHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileCertificateId = certificateId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.certificateRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.certificateHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{certificateId}") public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) { const _record = await this.certificateRepo.findOneBy({ id: certificateId }); diff --git a/src/controllers/ProfileCertificateEmployeeTempController.ts b/src/controllers/ProfileCertificateEmployeeTempController.ts index f5619023..8ad0fa3f 100644 --- a/src/controllers/ProfileCertificateEmployeeTempController.ts +++ b/src/controllers/ProfileCertificateEmployeeTempController.ts @@ -162,6 +162,45 @@ export class ProfileCertificateEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลใบอนุญาตประกอบวิชาชีพ + * @summary API ลบข้อมูลใบอนุญาตประกอบวิชาชีพ + * @param certificateId คีย์ใบอนุญาตประกอบวิชาชีพ + */ + @Patch("update-delete/{certificateId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() certificateId: string, + ) { + const record = await this.certificateRepo.findOneBy({ id: certificateId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileCertificateHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileCertificateId = certificateId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.certificateRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.certificateHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{certificateId}") public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileChangeNameController.ts b/src/controllers/ProfileChangeNameController.ts index 5b772f12..26741c46 100644 --- a/src/controllers/ProfileChangeNameController.ts +++ b/src/controllers/ProfileChangeNameController.ts @@ -191,6 +191,45 @@ export class ProfileChangeNameController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประวัติการเปลี่ยนชื่อ - นามสกุล + * @summary API ลบข้อมูลประวัติการเปลี่ยนชื่อ - นามสกุล + * @param trainingId คีย์ประวัติการเปลี่ยนชื่อ - นามสกุล + */ + @Patch("update-delete/{changeNameId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() changeNameId: string, + ) { + const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileChangeNameHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileChangeNameId = changeNameId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.changeNameRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.changeNameHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{changeNameId}") public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) { const _record = await this.changeNameRepository.findOneBy({ id: changeNameId }); diff --git a/src/controllers/ProfileChangeNameEmployeeController.ts b/src/controllers/ProfileChangeNameEmployeeController.ts index 547368e1..7772646d 100644 --- a/src/controllers/ProfileChangeNameEmployeeController.ts +++ b/src/controllers/ProfileChangeNameEmployeeController.ts @@ -189,6 +189,45 @@ export class ProfileChangeNameEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประวัติการเปลี่ยนชื่อ - นามสกุล + * @summary API ลบข้อมูลประวัติการเปลี่ยนชื่อ - นามสกุล + * @param trainingId คีย์ประวัติการเปลี่ยนชื่อ - นามสกุล + */ + @Patch("update-delete/{changeNameId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() changeNameId: string, + ) { + const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileChangeNameHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileChangeNameId = changeNameId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.changeNameRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.changeNameHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{changeNameId}") public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) { const _record = await this.changeNameRepository.findOneBy({ id: changeNameId }); diff --git a/src/controllers/ProfileChangeNameEmployeeTempController.ts b/src/controllers/ProfileChangeNameEmployeeTempController.ts index f7a141f7..049e2b07 100644 --- a/src/controllers/ProfileChangeNameEmployeeTempController.ts +++ b/src/controllers/ProfileChangeNameEmployeeTempController.ts @@ -181,6 +181,45 @@ export class ProfileChangeNameEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประวัติการเปลี่ยนชื่อ - นามสกุล + * @summary API ลบข้อมูลประวัติการเปลี่ยนชื่อ - นามสกุล + * @param trainingId คีย์ประวัติการเปลี่ยนชื่อ - นามสกุล + */ + @Patch("update-delete/{changeNameId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() changeNameId: string, + ) { + const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileChangeNameHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileChangeNameId = changeNameId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.changeNameRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.changeNameHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{changeNameId}") public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileChildrenController.ts b/src/controllers/ProfileChildrenController.ts index 577b6781..98319cf0 100644 --- a/src/controllers/ProfileChildrenController.ts +++ b/src/controllers/ProfileChildrenController.ts @@ -143,6 +143,45 @@ export class ProfileChildrenController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลบุตร + * @summary API ลบข้อมูลบุตร + * @param trainingId คีย์บุตร + */ + @Patch("update-delete/{childrenId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() childrenId: string, + ) { + const record = await this.childrenRepository.findOneBy({ id: childrenId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileChildrenHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileChildrenId = childrenId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.childrenRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.childrenHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{childrenId}") public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) { const _record = await this.childrenRepository.findOneBy({ id: childrenId }); diff --git a/src/controllers/ProfileChildrenEmployeeController.ts b/src/controllers/ProfileChildrenEmployeeController.ts index 7a0cd772..2be404ef 100644 --- a/src/controllers/ProfileChildrenEmployeeController.ts +++ b/src/controllers/ProfileChildrenEmployeeController.ts @@ -156,6 +156,45 @@ export class ProfileChildrenEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลบุตร + * @summary API ลบข้อมูลบุตร + * @param trainingId คีย์บุตร + */ + @Patch("update-delete/{childrenId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() childrenId: string, + ) { + const record = await this.childrenRepository.findOneBy({ id: childrenId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileChildrenHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileChildrenId = childrenId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.childrenRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.childrenHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{childrenId}") public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) { const _record = await this.childrenRepository.findOneBy({ id: childrenId }); diff --git a/src/controllers/ProfileChildrenEmployeeTempController.ts b/src/controllers/ProfileChildrenEmployeeTempController.ts index 2134e954..83a04a30 100644 --- a/src/controllers/ProfileChildrenEmployeeTempController.ts +++ b/src/controllers/ProfileChildrenEmployeeTempController.ts @@ -143,6 +143,45 @@ export class ProfileChildrenEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลบุตร + * @summary API ลบข้อมูลบุตร + * @param trainingId คีย์บุตร + */ + @Patch("update-delete/{childrenId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() childrenId: string, + ) { + const record = await this.childrenRepository.findOneBy({ id: childrenId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileChildrenHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileChildrenId = childrenId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.childrenRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.childrenHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{childrenId}") public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileDisciplineController.ts b/src/controllers/ProfileDisciplineController.ts index e7ec5a94..17cf3689 100644 --- a/src/controllers/ProfileDisciplineController.ts +++ b/src/controllers/ProfileDisciplineController.ts @@ -175,6 +175,45 @@ export class ProfileDisciplineController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลวินัย + * @summary API ลบข้อมูลวินัย + * @param disciplineId คีย์วินัย + */ + @Patch("update-delete/{disciplineId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() disciplineId: string, + ) { + const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileDisciplineHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileDisciplineId = disciplineId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.disciplineRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.disciplineHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{disciplineId}") public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) { const _record = await this.disciplineRepository.findOneBy({ id: disciplineId }); diff --git a/src/controllers/ProfileDisciplineEmployeeController.ts b/src/controllers/ProfileDisciplineEmployeeController.ts index 22dd3f24..44460d44 100644 --- a/src/controllers/ProfileDisciplineEmployeeController.ts +++ b/src/controllers/ProfileDisciplineEmployeeController.ts @@ -179,6 +179,45 @@ export class ProfileDisciplineEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลวินัย + * @summary API ลบข้อมูลวินัย + * @param disciplineId คีย์วินัย + */ + @Patch("update-delete/{disciplineId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() disciplineId: string, + ) { + const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileDisciplineHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileDisciplineId = disciplineId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.disciplineRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.disciplineHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{disciplineId}") public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) { const _record = await this.disciplineRepository.findOneBy({ id: disciplineId }); diff --git a/src/controllers/ProfileDisciplineEmployeeTempController.ts b/src/controllers/ProfileDisciplineEmployeeTempController.ts index b1100ab2..7699b8ac 100644 --- a/src/controllers/ProfileDisciplineEmployeeTempController.ts +++ b/src/controllers/ProfileDisciplineEmployeeTempController.ts @@ -169,6 +169,45 @@ export class ProfileDisciplineEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลวินัย + * @summary API ลบข้อมูลวินัย + * @param disciplineId คีย์วินัย + */ + @Patch("update-delete/{disciplineId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() disciplineId: string, + ) { + const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileDisciplineHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileDisciplineId = disciplineId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.disciplineRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.disciplineHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{disciplineId}") public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileDutyController.ts b/src/controllers/ProfileDutyController.ts index 43161383..15bcf53e 100644 --- a/src/controllers/ProfileDutyController.ts +++ b/src/controllers/ProfileDutyController.ts @@ -150,6 +150,45 @@ export class ProfileDutyController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลปฏิบัติราชการพิเศษ + * @summary API ลบข้อมูลปฏิบัติราชการพิเศษ + * @param dutyId คีย์ปฏิบัติราชการพิเศษ + */ + @Patch("update-delete/{dutyId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() dutyId: string, + ) { + const record = await this.dutyRepository.findOneBy({ id: dutyId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileDutyHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileDutyId = dutyId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.dutyRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.dutyHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{dutyId}") public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) { const _record = await this.dutyRepository.findOneBy({ id: dutyId }); diff --git a/src/controllers/ProfileDutyEmployeeController.ts b/src/controllers/ProfileDutyEmployeeController.ts index 82a3e9b4..278cd736 100644 --- a/src/controllers/ProfileDutyEmployeeController.ts +++ b/src/controllers/ProfileDutyEmployeeController.ts @@ -159,6 +159,45 @@ export class ProfileDutyEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลปฏิบัติราชการพิเศษ + * @summary API ลบข้อมูลปฏิบัติราชการพิเศษ + * @param dutyId คีย์ปฏิบัติราชการพิเศษ + */ + @Patch("update-delete/{dutyId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() dutyId: string, + ) { + const record = await this.dutyRepository.findOneBy({ id: dutyId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileDutyHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileDutyId = dutyId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.dutyRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.dutyHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{dutyId}") public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) { const _record = await this.dutyRepository.findOneBy({ id: dutyId }); diff --git a/src/controllers/ProfileDutyEmployeeTempController.ts b/src/controllers/ProfileDutyEmployeeTempController.ts index 09f8f843..fa3cc605 100644 --- a/src/controllers/ProfileDutyEmployeeTempController.ts +++ b/src/controllers/ProfileDutyEmployeeTempController.ts @@ -148,6 +148,45 @@ export class ProfileDutyEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลปฏิบัติราชการพิเศษ + * @summary API ลบข้อมูลปฏิบัติราชการพิเศษ + * @param dutyId คีย์ปฏิบัติราชการพิเศษ + */ + @Patch("update-delete/{dutyId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() dutyId: string, + ) { + const record = await this.dutyRepository.findOneBy({ id: dutyId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileDutyHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileDutyId = dutyId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.dutyRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.dutyHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{dutyId}") public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileEducationsController.ts b/src/controllers/ProfileEducationsController.ts index e9013eea..8ac2d34c 100644 --- a/src/controllers/ProfileEducationsController.ts +++ b/src/controllers/ProfileEducationsController.ts @@ -208,6 +208,45 @@ export class ProfileEducationsController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประวัติการศึกษา + * @summary API ลบข้อมูลประวัติการศึกษา/ดูงาน + * @param educationId คีย์ประวัติการศึกษา + */ + @Patch("update-delete/{educationId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() educationId: string, + ) { + const record = await this.profileEducationRepo.findOneBy({ id: educationId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileEducationHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileEducationId = educationId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileEducationRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileEducationHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{educationId}") public async deleteProfileEducation( @Path() educationId: string, diff --git a/src/controllers/ProfileEducationsEmployeeController.ts b/src/controllers/ProfileEducationsEmployeeController.ts index c81a7309..0775d53a 100644 --- a/src/controllers/ProfileEducationsEmployeeController.ts +++ b/src/controllers/ProfileEducationsEmployeeController.ts @@ -220,6 +220,45 @@ export class ProfileEducationsEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประวัติการศึกษา + * @summary API ลบข้อมูลประวัติการศึกษา/ดูงาน + * @param educationId คีย์ประวัติการศึกษา + */ + @Patch("update-delete/{educationId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() educationId: string, + ) { + const record = await this.profileEducationRepo.findOneBy({ id: educationId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileEducationHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileEducationId = educationId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileEducationRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileEducationHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{educationId}") public async deleteProfileEducation( @Path() educationId: string, diff --git a/src/controllers/ProfileEducationsEmployeeTempController.ts b/src/controllers/ProfileEducationsEmployeeTempController.ts index a63c88f7..a0688591 100644 --- a/src/controllers/ProfileEducationsEmployeeTempController.ts +++ b/src/controllers/ProfileEducationsEmployeeTempController.ts @@ -210,6 +210,45 @@ export class ProfileEducationsEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประวัติการศึกษา + * @summary API ลบข้อมูลประวัติการศึกษา/ดูงาน + * @param educationId คีย์ประวัติการศึกษา + */ + @Patch("update-delete/{educationId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() educationId: string, + ) { + const record = await this.profileEducationRepo.findOneBy({ id: educationId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileEducationHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileEducationId = educationId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.profileEducationRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.profileEducationHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{educationId}") public async deleteProfileEducation( @Path() educationId: string, diff --git a/src/controllers/ProfileHonorController.ts b/src/controllers/ProfileHonorController.ts index 057f6ad0..1eb6cba4 100644 --- a/src/controllers/ProfileHonorController.ts +++ b/src/controllers/ProfileHonorController.ts @@ -176,6 +176,45 @@ export class ProfileHonorController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประกาศเกียรติคุณ + * @summary API ลบข้อมูลประกาศเกียรติคุณ + * @param honorId คีย์ประกาศเกียรติคุณ + */ + @Patch("update-delete/{honorId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() honorId: string, + ) { + const record = await this.honorRepo.findOneBy({ id: honorId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileHonorHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileHonorId = honorId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.honorRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.honorHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{honorId}") public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) { const _record = await this.honorRepo.findOneBy({ id: honorId }); diff --git a/src/controllers/ProfileHonorEmployeeController.ts b/src/controllers/ProfileHonorEmployeeController.ts index bacb5ca5..5ab8df44 100644 --- a/src/controllers/ProfileHonorEmployeeController.ts +++ b/src/controllers/ProfileHonorEmployeeController.ts @@ -188,6 +188,45 @@ export class ProfileHonorEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประกาศเกียรติคุณ + * @summary API ลบข้อมูลประกาศเกียรติคุณ + * @param honorId คีย์ประกาศเกียรติคุณ + */ + @Patch("update-delete/{honorId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() honorId: string, + ) { + const record = await this.honorRepo.findOneBy({ id: honorId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileHonorHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileHonorId = honorId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.honorRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.honorHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{honorId}") public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) { const _record = await this.honorRepo.findOneBy({ id: honorId }); diff --git a/src/controllers/ProfileHonorEmployeeTempController.ts b/src/controllers/ProfileHonorEmployeeTempController.ts index dbf1ceb3..eeba94e8 100644 --- a/src/controllers/ProfileHonorEmployeeTempController.ts +++ b/src/controllers/ProfileHonorEmployeeTempController.ts @@ -176,6 +176,45 @@ export class ProfileHonorEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลประกาศเกียรติคุณ + * @summary API ลบข้อมูลประกาศเกียรติคุณ + * @param honorId คีย์ประกาศเกียรติคุณ + */ + @Patch("update-delete/{honorId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() honorId: string, + ) { + const record = await this.honorRepo.findOneBy({ id: honorId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileHonorHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileHonorId = honorId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.honorRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.honorHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{honorId}") public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileInsigniaController.ts b/src/controllers/ProfileInsigniaController.ts index af871c69..f4f5f2b4 100644 --- a/src/controllers/ProfileInsigniaController.ts +++ b/src/controllers/ProfileInsigniaController.ts @@ -199,6 +199,45 @@ export class ProfileInsigniaController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลเครื่องราชอิสริยาภรณ์ + * @summary API ลบข้อมูลเครื่องราชอิสริยาภรณ์ + * @param insigniaId คีย์เครื่องราชอิสริยาภรณ์ + */ + @Patch("update-delete/{insigniaId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() insigniaId: string, + ) { + const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileInsigniaHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileInsigniaId = insigniaId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.insigniaRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.insigniaHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{insigniaId}") public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) { const _record = await this.insigniaRepo.findOneBy({ id: insigniaId }); diff --git a/src/controllers/ProfileInsigniaEmployeeController.ts b/src/controllers/ProfileInsigniaEmployeeController.ts index e0d3ad82..7e9d11b2 100644 --- a/src/controllers/ProfileInsigniaEmployeeController.ts +++ b/src/controllers/ProfileInsigniaEmployeeController.ts @@ -207,6 +207,45 @@ export class ProfileInsigniaEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลเครื่องราชอิสริยาภรณ์ + * @summary API ลบข้อมูลเครื่องราชอิสริยาภรณ์ + * @param insigniaId คีย์เครื่องราชอิสริยาภรณ์ + */ + @Patch("update-delete/{insigniaId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() insigniaId: string, + ) { + const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileInsigniaHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileInsigniaId = insigniaId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.insigniaRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.insigniaHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{insigniaId}") public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) { const _record = await this.insigniaRepo.findOneBy({ id: insigniaId }); diff --git a/src/controllers/ProfileInsigniaEmployeeTempController.ts b/src/controllers/ProfileInsigniaEmployeeTempController.ts index 6f11cec3..56bf0c34 100644 --- a/src/controllers/ProfileInsigniaEmployeeTempController.ts +++ b/src/controllers/ProfileInsigniaEmployeeTempController.ts @@ -196,6 +196,45 @@ export class ProfileInsigniaEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลเครื่องราชอิสริยาภรณ์ + * @summary API ลบข้อมูลเครื่องราชอิสริยาภรณ์ + * @param insigniaId คีย์เครื่องราชอิสริยาภรณ์ + */ + @Patch("update-delete/{insigniaId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() insigniaId: string, + ) { + const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileInsigniaHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileInsigniaId = insigniaId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.insigniaRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.insigniaHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{insigniaId}") public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index a6624bbb..c61b3d95 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -265,6 +265,45 @@ export class ProfileLeaveController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลการลา + * @summary API ลบข้อมูลการลา + * @param leaveId คีย์การลา + */ + @Patch("update-delete/{leaveId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() leaveId: string, + ) { + const record = await this.leaveRepo.findOneBy({ id: leaveId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileLeaveHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileLeaveId = leaveId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.leaveRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.leaveHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Patch("cancel/{leaveId}") public async updateCancel( @Request() req: RequestWithUser, diff --git a/src/controllers/ProfileLeaveEmployeeController.ts b/src/controllers/ProfileLeaveEmployeeController.ts index ade4a5c4..9f928776 100644 --- a/src/controllers/ProfileLeaveEmployeeController.ts +++ b/src/controllers/ProfileLeaveEmployeeController.ts @@ -192,6 +192,45 @@ export class ProfileLeaveEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลการลา + * @summary API ลบข้อมูลการลา + * @param leaveId คีย์การลา + */ + @Patch("update-delete/{leaveId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() leaveId: string, + ) { + const record = await this.leaveRepo.findOneBy({ id: leaveId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileLeaveHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileLeaveId = leaveId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.leaveRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.leaveHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{leaveId}") public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) { const _record = await this.leaveRepo.findOneBy({ id: leaveId }); diff --git a/src/controllers/ProfileLeaveEmployeeTempController.ts b/src/controllers/ProfileLeaveEmployeeTempController.ts index 85960fa5..a8aa979f 100644 --- a/src/controllers/ProfileLeaveEmployeeTempController.ts +++ b/src/controllers/ProfileLeaveEmployeeTempController.ts @@ -179,6 +179,45 @@ export class ProfileLeaveEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลการลา + * @summary API ลบข้อมูลการลา + * @param leaveId คีย์การลา + */ + @Patch("update-delete/{leaveId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() leaveId: string, + ) { + const record = await this.leaveRepo.findOneBy({ id: leaveId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileLeaveHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileLeaveId = leaveId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.leaveRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.leaveHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{leaveId}") public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileNopaidController.ts b/src/controllers/ProfileNopaidController.ts index d0760d13..b9cecc1d 100644 --- a/src/controllers/ProfileNopaidController.ts +++ b/src/controllers/ProfileNopaidController.ts @@ -140,6 +140,45 @@ export class ProfileNopaidController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลบันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + * @summary API ลบข้อมูลบันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + * @param nopaidId คีย์บันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + */ + @Patch("update-delete/{nopaidId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() nopaidId: string, + ) { + const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileNopaidHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileNopaidId = nopaidId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.nopaidRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.nopaidHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{nopaidId}") public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) { const _record = await this.nopaidRepository.findOneBy({ id: nopaidId }); diff --git a/src/controllers/ProfileNopaidEmployeeController.ts b/src/controllers/ProfileNopaidEmployeeController.ts index e5849e8e..5a10ee75 100644 --- a/src/controllers/ProfileNopaidEmployeeController.ts +++ b/src/controllers/ProfileNopaidEmployeeController.ts @@ -147,6 +147,45 @@ export class ProfileNopaidEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลบันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + * @summary API ลบข้อมูลบันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + * @param nopaidId คีย์บันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + */ + @Patch("update-delete/{nopaidId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() nopaidId: string, + ) { + const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileNopaidHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileNopaidId = nopaidId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.nopaidRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.nopaidHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{nopaidId}") public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) { const _record = await this.nopaidRepository.findOneBy({ id: nopaidId }); diff --git a/src/controllers/ProfileNopaidEmployeeTempController.ts b/src/controllers/ProfileNopaidEmployeeTempController.ts index fe6edab3..ca9aa4a5 100644 --- a/src/controllers/ProfileNopaidEmployeeTempController.ts +++ b/src/controllers/ProfileNopaidEmployeeTempController.ts @@ -144,6 +144,45 @@ export class ProfileNopaidEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลบันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + * @summary API ลบข้อมูลบันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + * @param nopaidId คีย์บันทึกวันที่ไม่ได้รับเงินเงินเดือนฯ + */ + @Patch("update-delete/{nopaidId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() nopaidId: string, + ) { + const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileNopaidHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileNopaidId = nopaidId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.nopaidRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.nopaidHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{nopaidId}") public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileOtherController.ts b/src/controllers/ProfileOtherController.ts index 430af83e..6f774c3b 100644 --- a/src/controllers/ProfileOtherController.ts +++ b/src/controllers/ProfileOtherController.ts @@ -149,6 +149,45 @@ export class ProfileOtherController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลข้อมูลอื่นๆ + * @summary API ลบข้อมูลข้อมูลอื่นๆ + * @param otherId คีย์ข้อมูลอื่นๆ + */ + @Patch("update-delete/{otherId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() otherId: string, + ) { + const record = await this.otherRepository.findOneBy({ id: otherId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_OFFICER", record.profileId); + const before = structuredClone(record); + const history = new ProfileOtherHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileOtherId = otherId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.otherRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.otherHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{otherId}") public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) { const _record = await this.otherRepository.findOneBy({ id: otherId }); diff --git a/src/controllers/ProfileOtherEmployeeController.ts b/src/controllers/ProfileOtherEmployeeController.ts index c8894afe..fe1adf94 100644 --- a/src/controllers/ProfileOtherEmployeeController.ts +++ b/src/controllers/ProfileOtherEmployeeController.ts @@ -160,6 +160,45 @@ export class ProfileOtherEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลข้อมูลอื่นๆ + * @summary API ลบข้อมูลข้อมูลอื่นๆ + * @param otherId คีย์ข้อมูลอื่นๆ + */ + @Patch("update-delete/{otherId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() otherId: string, + ) { + const record = await this.otherRepository.findOneBy({ id: otherId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileOtherHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileOtherId = otherId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.otherRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.otherHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{otherId}") public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) { const _record = await this.otherRepository.findOneBy({ id: otherId }); diff --git a/src/controllers/ProfileOtherEmployeeTempController.ts b/src/controllers/ProfileOtherEmployeeTempController.ts index c20914fe..7f672ce1 100644 --- a/src/controllers/ProfileOtherEmployeeTempController.ts +++ b/src/controllers/ProfileOtherEmployeeTempController.ts @@ -148,6 +148,45 @@ export class ProfileOtherEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลข้อมูลอื่นๆ + * @summary API ลบข้อมูลข้อมูลอื่นๆ + * @param otherId คีย์ข้อมูลอื่นๆ + */ + @Patch("update-delete/{otherId}") + public async updateIsDeleted( + @Request() req: RequestWithUser, + @Path() otherId: string, + ) { + const record = await this.otherRepository.findOneBy({ id: otherId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileOtherHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileOtherId = otherId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.otherRepository.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.otherHistoryRepository.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{otherId}") public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); diff --git a/src/controllers/ProfileTrainingEmployeeController.ts b/src/controllers/ProfileTrainingEmployeeController.ts index d9f824a8..73bbc5cf 100644 --- a/src/controllers/ProfileTrainingEmployeeController.ts +++ b/src/controllers/ProfileTrainingEmployeeController.ts @@ -168,6 +168,45 @@ export class ProfileTrainingEmployeeController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลการฝึกอบรม/ดูงาน + * @summary API ลบข้อมูลการฝึกอบรม/ดูงาน + * @param trainingId คีย์การฝึกอบรม/ดูงาน + */ + @Patch("update-delete/{trainingId}") + public async updateIsDeletedTraining( + @Request() req: RequestWithUser, + @Path() trainingId: string, + ) { + const record = await this.trainingRepo.findOneBy({ id: trainingId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", record.profileEmployeeId); + const before = structuredClone(record); + const history = new ProfileTrainingHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileTrainingId = trainingId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.trainingRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.trainingHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{trainingId}") public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) { const _record = await this.trainingRepo.findOneBy({ id: trainingId }); diff --git a/src/controllers/ProfileTrainingEmployeeTempController.ts b/src/controllers/ProfileTrainingEmployeeTempController.ts index 46e1686e..ace30f6d 100644 --- a/src/controllers/ProfileTrainingEmployeeTempController.ts +++ b/src/controllers/ProfileTrainingEmployeeTempController.ts @@ -156,6 +156,45 @@ export class ProfileTrainingEmployeeTempController extends Controller { return new HttpSuccess(); } + /** + * API ลบข้อมูลการฝึกอบรม/ดูงาน + * @summary API ลบข้อมูลการฝึกอบรม/ดูงาน + * @param trainingId คีย์การฝึกอบรม/ดูงาน + */ + @Patch("update-delete/{trainingId}") + public async updateIsDeletedTraining( + @Request() req: RequestWithUser, + @Path() trainingId: string, + ) { + const record = await this.trainingRepo.findOneBy({ id: trainingId }); + if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + if (record.isDeleted === true) { + return new HttpSuccess(); + } + await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP"); + const before = structuredClone(record); + const history = new ProfileTrainingHistory(); + const now = new Date(); + record.isDeleted = true; + record.lastUpdateUserId = req.user.sub; + record.lastUpdateFullName = req.user.name; + record.lastUpdatedAt = now; + + Object.assign(history, { ...record, id: undefined }); + history.profileTrainingId = trainingId; + history.createdUserId = req.user.sub; + history.createdFullName = req.user.name; + history.createdAt = now; + + await Promise.all([ + this.trainingRepo.save(record, { data: req }), + setLogDataDiff(req, { before, after: record }), + this.trainingHistoryRepo.save(history, { data: req }), + ]); + + return new HttpSuccess(); + } + @Delete("{trainingId}") public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) { await new permission().PermissionDelete(req, "SYS_REGISTRY_TEMP");