From 0f45c75d62a292e89d48b39da5a027a43b029aee Mon Sep 17 00:00:00 2001 From: AdisakKanthawilang Date: Fri, 2 May 2025 13:29:12 +0700 Subject: [PATCH] fix --- src/controllers/ProfileLeaveController.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/controllers/ProfileLeaveController.ts b/src/controllers/ProfileLeaveController.ts index bc2b07ba..794c5785 100644 --- a/src/controllers/ProfileLeaveController.ts +++ b/src/controllers/ProfileLeaveController.ts @@ -26,6 +26,7 @@ import { Profile } from "../entities/Profile"; import { LeaveType } from "../entities/LeaveType"; import permission from "../interfaces/permission"; import { setLogDataDiff } from "../interfaces/utils"; +import { Not } from "typeorm"; @Route("api/v1/org/profile/leave") @Tags("ProfileLeave") @Security("bearerAuth") @@ -132,7 +133,7 @@ export class ProfileLeaveController extends Controller { await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", profileId); const record = await this.leaveRepo.find({ relations: { leaveType: true }, - where: { profileId }, + where: { profileId: profileId, status: Not("cancel") }, order: { createdAt: "ASC" }, }); return new HttpSuccess(record); @@ -269,26 +270,15 @@ export class ProfileLeaveController extends Controller { if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลการลา"); const before = structuredClone(record); - const history = new ProfileLeaveHistory(); - Object.assign(history, { ...record, id: undefined }); - - record.status = "CANCEL"; - history.profileLeaveId = leaveId; + record.status = "cancel"; record.lastUpdateUserId = req.user.sub; record.lastUpdateFullName = req.user.name; record.lastUpdatedAt = new Date(); - history.lastUpdateUserId = req.user.sub; - history.lastUpdateFullName = req.user.name; - history.createdUserId = req.user.sub; - history.createdFullName = req.user.name; - history.createdAt = new Date(); - history.lastUpdatedAt = new Date(); await Promise.all([ this.leaveRepo.save(record, { data: req }), setLogDataDiff(req, { before, after: record }), - this.leaveHistoryRepo.save(history, { data: req }), ]); return new HttpSuccess();