From 6b89316ab6b8d1cf47dc90959fb2dcb9f14c41e3 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Thu, 11 Jul 2024 12:44:56 +0700 Subject: [PATCH] =?UTF-8?q?fix=20:=20API=20=E0=B8=A5=E0=B8=87=E0=B9=80?= =?UTF-8?q?=E0=B8=A7=E0=B8=A5=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Leave/Controllers/LeaveController.cs | 38 +++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index 6c08b893..7ac36952 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -2,6 +2,7 @@ using BMA.EHR.Application.Repositories.Commands; using BMA.EHR.Application.Repositories.Leaves.LeaveRequests; using BMA.EHR.Application.Repositories.Leaves.TimeAttendants; +using BMA.EHR.Application.Responses.Profiles; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Models.Leave.TimeAttendants; using BMA.EHR.Domain.Shared; @@ -842,13 +843,15 @@ namespace BMA.EHR.Leave.Service.Controllers return Error(new Exception("วันเริ่มต้นต้องมีค่าน้อยกว่าหรือเท่ากับวันสิ้นสุด"), StatusCodes.Status400BadRequest); } - var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); + var profiles = new List(); - 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); + //} var defaultRound = await _dutyTimeRepository.GetDefaultAsync(); if (defaultRound == null) @@ -857,11 +860,12 @@ namespace BMA.EHR.Leave.Service.Controllers } //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 effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id); + //var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; + //var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); - var duty = userRound ?? defaultRound; + //var duty = userRound ?? defaultRound; + var duty = defaultRound; var checkin_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.StartTimeMorning}"); var checkout_base = DateTime.Parse($"{DateTime.Now.ToString("yyyy-MM-dd")} {duty.EndTimeAfternoon}"); @@ -875,8 +879,18 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var d in resultData) { - var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId, AccessToken); - if (pf == null) continue; + var pf = profiles.FirstOrDefault(x => x.Keycloak == d.KeycloakUserId); + if (pf == null) + { + pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId, AccessToken); + if (pf == null) + continue; + else + profiles.Add(pf); + } + + //var pf = await _userProfileRepository.GetProfileByKeycloakIdAsync(d.KeycloakUserId, AccessToken); + //if (pf == null) continue; data.Add(new CheckInProcessHistoryForAdminDto { Id = d.Id,