Refactor LeaveController to streamline profile retrieval and duty time handling

This commit is contained in:
Suphonchai Phoonsawat 2026-04-01 12:24:00 +07:00
parent 8fa105606b
commit 1cf780ecd0
2 changed files with 19 additions and 13 deletions

View file

@ -3277,16 +3277,15 @@ namespace BMA.EHR.Leave.Service.Controllers
foreach (var data in rawDataPaged)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdNewAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
UserDutyTime? effectiveDate = null;
if (profile != null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
//return Error($"{data.Id} PF{data.FirstName} {data.LastName} : {GlobalMessages.DataNotFound}", StatusCodes.Status404NotFound);
}
//var userRound = await _dutyTimeRepository.GetByIdAsync(profile.DutyTimeId ?? Guid.Empty);
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);
var checkInData = await _userTimeStampRepository.GetTimestampByDateAsync(data.KeycloakUserId, data.CheckDate);
var duty = userRound ?? getDefaultRound;