Compare commits

...

3 commits

Author SHA1 Message Date
Suphonchai Phoonsawat
d70ed254c0 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
2026-02-18 16:56:48 +07:00
Suphonchai Phoonsawat
de91fd0fa2 Refactor LeaveBeginningController to restore profile checks and reset leave days to zero 2026-02-18 16:47:14 +07:00
Suphonchai Phoonsawat
7d3ec6c74e Refactor ScheduleUpdateLeaveBeginningAsync to use ScheduleEditLeaveBeginningDto and remove unused profile checks 2026-02-18 16:34:35 +07:00
3 changed files with 52 additions and 17 deletions

View file

@ -500,7 +500,7 @@ namespace BMA.EHR.Leave.Service.Controllers
[HttpPut("schedule")]
[AllowAnonymous]
public async Task<ActionResult<ResponseObject>> ScheduleUpdateLeaveBeginningAsync([FromBody] EditLeaveBeginningDto req)
public async Task<ActionResult<ResponseObject>> ScheduleUpdateLeaveBeginningAsync([FromBody] ScheduleEditLeaveBeginningDto req)
{
try
{
@ -520,10 +520,10 @@ namespace BMA.EHR.Leave.Service.Controllers
oldData.LeaveTypeId = req.LeaveTypeId;
oldData.LeaveYear = req.LeaveYear;
oldData.LeaveDays = req.LeaveDays;
oldData.LeaveDaysUsed = req.LeaveDaysUsed;
oldData.LeaveCount = req.LeaveCount;
oldData.BeginningLeaveDays = req.BeginningLeaveDays;
oldData.BeginningLeaveCount = req.BeginningLeaveCount;
// oldData.LeaveDaysUsed = req.LeaveDaysUsed;
// oldData.LeaveCount = req.LeaveCount;
// oldData.BeginningLeaveDays = req.BeginningLeaveDays;
// oldData.BeginningLeaveCount = req.BeginningLeaveCount;
oldData.ProfileId = req.ProfileId;
oldData.Prefix = profile.Prefix;
@ -536,7 +536,7 @@ namespace BMA.EHR.Leave.Service.Controllers
oldData.Child4DnaId = profile.Child4DnaId;
oldData.LastUpdateUserId = "";
oldData.LastUpdateFullName = FullName ?? "";
oldData.LastUpdateFullName = "System";
oldData.LastUpdatedAt = DateTime.Now;
await _leaveBeginningRepository.UpdateAsync(oldData);
@ -547,10 +547,10 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveBeginning.LeaveTypeId = req.LeaveTypeId;
leaveBeginning.LeaveYear = req.LeaveYear;
leaveBeginning.LeaveDays = req.LeaveDays;
leaveBeginning.LeaveDaysUsed = req.LeaveDaysUsed;
leaveBeginning.LeaveCount = req.LeaveCount;
leaveBeginning.BeginningLeaveDays = req.BeginningLeaveDays;
leaveBeginning.BeginningLeaveCount = req.BeginningLeaveCount;
leaveBeginning.LeaveDaysUsed = 0;
leaveBeginning.LeaveCount = 0;
leaveBeginning.BeginningLeaveDays = 0;
leaveBeginning.BeginningLeaveCount = 0;
leaveBeginning.ProfileId = req.ProfileId;
leaveBeginning.Prefix = profile.Prefix;
@ -564,7 +564,7 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveBeginning.Child4DnaId = profile.Child4DnaId;
leaveBeginning.CreatedUserId = "";
leaveBeginning.CreatedFullName = FullName ?? "";
leaveBeginning.CreatedFullName = "System";
leaveBeginning.CreatedAt = DateTime.Now;
await _leaveBeginningRepository.AddAsync(leaveBeginning);

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")

View file

@ -29,4 +29,20 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveBeginnings
[Comment("จำนวนครั้งที่ลายกมา")]
public int BeginningLeaveCount { get; set; } = 0;
}
public class ScheduleEditLeaveBeginningDto
{
[Required]
public Guid ProfileId { get; set; } = Guid.Empty;
[Required]
public Guid LeaveTypeId { get; set; } = Guid.Empty;
[Required, Comment("ปีงบประมาณ")]
public int LeaveYear { get; set; } = 0;
[Required, Comment("จำนวนวันลายกมา")]
public double LeaveDays { get; set; } = 0.0;
}
}