Enhance LeaveRequestController to restore profile checks and implement officer notification logic #2164
All checks were successful
Build & Deploy Leave Service / build (push) Successful in 1m34s

This commit is contained in:
Suphonchai Phoonsawat 2026-02-18 16:56:48 +07:00
parent de91fd0fa2
commit d70ed254c0

View file

@ -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<Notification>().Add(noti);
}
await _appDbContext.SaveChangesAsync();
}
// var baseAPIOrg = _configuration["API"];
// var apiUrlOrg = $"{baseAPIOrg}/org/workflow/add-workflow";
// if (profile.ProfileType == "OFFICER")