Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop
This commit is contained in:
commit
ee2aa136b9
15 changed files with 1356 additions and 102 deletions
|
|
@ -43,6 +43,8 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
protected string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ namespace BMA.EHR.Application.Repositories.Leaves
|
|||
|
||||
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
protected string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId);
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken ?? "");
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -292,7 +292,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
}
|
||||
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId);
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken ?? "");
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -312,7 +312,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
// insert to profile leave
|
||||
var profileLeave = await _appDbContext.Set<ProfileLeave>()
|
||||
.Where(x => x.TypeLeave.Id == leaveType.Id)
|
||||
.Where(x => x.Profile.Id == profile.Id)
|
||||
.Where(x => x.ProfileId == profile.Id)
|
||||
.Where(x => x.DateStartLeave == rawData.LeaveStartDate && x.DateEndLeave == rawData.LeaveEndDate)
|
||||
.FirstOrDefaultAsync();
|
||||
if (profileLeave != null)
|
||||
|
|
@ -404,7 +404,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้");
|
||||
}
|
||||
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId);
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId,AccessToken);
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -430,7 +430,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
Status = "approve",
|
||||
Reason = rawData.LeaveDetail,
|
||||
|
||||
Profile = profile,
|
||||
ProfileId = profile.Id, // change from profile object to id
|
||||
TypeLeave = leaveType
|
||||
};
|
||||
_appDbContext.Set<ProfileLeave>().Add(profileLeave);
|
||||
|
|
@ -464,7 +464,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
throw new Exception("คำขอนี้ยังไม่ได้รับการอนุมัติจากผู้บังคับบัญชา ไม่สามารถทำรายการได้");
|
||||
}
|
||||
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId);
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(rawData.KeycloakUserId, AccessToken);
|
||||
if (profile == null)
|
||||
{
|
||||
throw new Exception(GlobalMessages.DataNotFound);
|
||||
|
|
@ -516,11 +516,11 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
|
|||
return 0.0;
|
||||
}
|
||||
|
||||
public async Task<double> GetSumApproveLeaveByRangeForUser(Guid keycloakUserId,DateTime startDate, DateTime endDate)
|
||||
public async Task<double> GetSumApproveLeaveByRangeForUser(Guid keycloakUserId, DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var data = await _dbContext.Set<LeaveRequest>().AsQueryable()
|
||||
.Include(x => x.Type)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.KeycloakUserId == keycloakUserId)
|
||||
.Where(x => x.LeaveStartDate.Date >= startDate.Date && x.LeaveStartDate.Date <= endDate.Date)
|
||||
.Where(x => x.LeaveStatus == "APPROVE")
|
||||
.ToListAsync();
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
await base.AddAsync(entity);
|
||||
|
||||
var userId = UserId != null ? Guid.Parse(UserId) : Guid.Empty;
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId);
|
||||
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? "");
|
||||
var profile_id = profile == null ? Guid.Empty : profile.Id;
|
||||
|
||||
var rootOc = _userProfileRepository.GetRootOcId(profile_id);
|
||||
|
|
@ -88,7 +88,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants
|
|||
|
||||
// send inbox and notification
|
||||
var subject_str = $"มีการขออนุมัติลงเวลากรณีพิเศษ";
|
||||
var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix.Name}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}";
|
||||
var body_str = $"โปรดพิจารณาคำร้องขอลงเวลาในกรณีพิเศษจาก {profile.Prefix}{profile.FirstName} {profile.LastName} ในวันที่ {entity.CheckDate.Date.ToThaiShortDate2()}";
|
||||
|
||||
var subject = subject_str;
|
||||
var body = body_str;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@ using BMA.EHR.Domain.Models.MetaData;
|
|||
using BMA.EHR.Domain.Models.Organizations;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
|
|
@ -61,18 +60,31 @@ namespace BMA.EHR.Application.Repositories
|
|||
return data;
|
||||
}
|
||||
|
||||
public async Task<Profile?> GetProfileByKeycloakIdAsync(Guid keycloakId)
|
||||
public async Task<GetProfileByKeycloakIdDto?> GetProfileByKeycloakIdAsync(Guid keycloakId, string? accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = await _dbContext.Set<Profile>().AsQueryable()
|
||||
.Include(p => p.Prefix)
|
||||
.Include(p => p.Position)
|
||||
.Include(p => p.PositionLevel)
|
||||
.Include(p => p.Salaries)
|
||||
.FirstOrDefaultAsync(p => p.KeycloakId == keycloakId);
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak/{keycloakId}";
|
||||
|
||||
return data;
|
||||
|
||||
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "");
|
||||
if (apiResult != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
|
||||
if (raw != null)
|
||||
return raw.Result;
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
//var data = await _dbContext.Set<Profile>().AsQueryable()
|
||||
// .Include(p => p.Prefix)
|
||||
// .Include(p => p.Position)
|
||||
// .Include(p => p.PositionLevel)
|
||||
// .Include(p => p.Salaries)
|
||||
// .FirstOrDefaultAsync(p => p.KeycloakId == keycloakId);
|
||||
|
||||
//return data;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue