api check-time แกะ profileId จาก token เพื่อไม่ต้องไป call เอาจาก org

This commit is contained in:
Suphonchai Phoonsawat 2026-05-05 21:23:46 +07:00
parent 82a45b6811
commit 654ec1e559

View file

@ -446,29 +446,30 @@ namespace BMA.EHR.Leave.Service.Controllers
public async Task<ActionResult<ResponseObject>> CheckTimeAsync(CancellationToken cancellationToken = default) public async Task<ActionResult<ResponseObject>> CheckTimeAsync(CancellationToken cancellationToken = default)
{ {
var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId); var userId = UserId == null ? Guid.Empty : Guid.Parse(UserId);
var profileId = ProfileId ?? Guid.Empty;
// Get user's last check-in record and profile in parallel // Get user's last check-in record and profile in parallel
var dataTask = _userTimeStampRepository.GetLastRecord(userId); var dataTask = _userTimeStampRepository.GetLastRecord(userId);
var profileTask = _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken); //var profileTask = _userProfileRepository.GetProfileByKeycloakIdNew2Async(userId, AccessToken);
var defaultRoundTask = _dutyTimeRepository.GetDefaultAsync(); var defaultRoundTask = _dutyTimeRepository.GetDefaultAsync();
await Task.WhenAll(dataTask, profileTask, defaultRoundTask); await Task.WhenAll(dataTask, defaultRoundTask);
var data = await dataTask; var data = await dataTask;
var profile = await profileTask; //var profile = await profileTask;
var getDefaultRound = await defaultRoundTask; var getDefaultRound = await defaultRoundTask;
if (profile == null) // if (profile == null)
{ // {
throw new Exception(GlobalMessages.DataNotFound); // throw new Exception(GlobalMessages.DataNotFound);
} // }
if (getDefaultRound == null) if (getDefaultRound == null)
{ {
return Error("ไม่พบรอบลงเวลา Default", StatusCodes.Status404NotFound); return Error("ไม่พบรอบลงเวลา Default", StatusCodes.Status404NotFound);
} }
var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profile.Id); var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(profileId);
var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty;
var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); var userRound = await _dutyTimeRepository.GetByIdAsync(roundId);