From d70ed254c0f6a3816edfeae47c028d28fbb8ac8d Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Wed, 18 Feb 2026 16:56:48 +0700 Subject: [PATCH] Enhance LeaveRequestController to restore profile checks and implement officer notification logic #2164 --- .../Controllers/LeaveRequestController.cs | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs index 6580dd53..a8a5e9b4 100644 --- a/BMA.EHR.Leave/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveRequestController.cs @@ -2323,12 +2323,31 @@ namespace BMA.EHR.Leave.Service.Controllers await _leaveRequestRepository.SendToOfficerAsync(id); // Remove Workflow Integration - // var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); - // var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); - // if (profile == null) - // { - // return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - // } + var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); + var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken); + if (profile == null) + { + return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); + } + + // Get Officer List + var officers = await _userProfileRepository.GetOCStaffAsync(profile.Id, AccessToken); + if(officers != null && officers.Count > 0) + { + foreach (var officer in officers) + { + // Send Notification + var noti = new Notification + { + Body = $"มีคำร้องขอลาจาก {profile.Prefix}{profile.FirstName} {profile.LastName} รอรับการอนุมัติจากคุณ", + ReceiverUserId = officer.ProfileId, + Type = "", + Payload = $"{URL}/leave/detail/{id}", + }; + _appDbContext.Set().Add(noti); + } + await _appDbContext.SaveChangesAsync(); + } // var baseAPIOrg = _configuration["API"]; // var apiUrlOrg = $"{baseAPIOrg}/org/workflow/add-workflow"; // if (profile.ProfileType == "OFFICER")