From cc902536d65dc5fe039a86c304e7f38763ba7755 Mon Sep 17 00:00:00 2001 From: Suphonchai Phoonsawat Date: Fri, 18 Aug 2023 10:53:44 +0700 Subject: [PATCH] fix bug and add approver position --- .../Commands/CommandRepository.cs | 32 ++++++++++++++----- .../Responses/OrganizationApproverResponse.cs | 11 +++++++ BMA.EHR.Command.Service/appsettings.json | 2 +- BMA.EHR.Command.Service/wwwroot/keycloak.json | 2 +- 4 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 BMA.EHR.Application/Responses/OrganizationApproverResponse.cs diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index eff28826..eee37b45 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -1220,7 +1220,7 @@ namespace BMA.EHR.Application.Repositories.Commands if (data == null) throw new Exception(GlobalMessages.OrganizationNotFound); - return data.OrganizationAgencyId!.Value; + return data.OrganizationAgencyId == null ? ocId : data.OrganizationAgencyId!.Value; } catch { @@ -1260,12 +1260,12 @@ namespace BMA.EHR.Application.Repositories.Commands } } - public async Task> GetOrgApproverAsync(Guid ocId) + public async Task> GetOrgApproverAsync(Guid ocId) { try { if (ocId == Guid.Empty) - return new List() { new KeyValueItemResponse { Id = Guid.Empty, Name = "ปลัดกรุงเทพมหานคร" } }; + return new List() { new OrganizationApproverResponse { Id = Guid.Empty, Name = "", PositionName = "ปลัดกรุงเทพมหานคร" } }; else { //var ret = new List(); @@ -1278,12 +1278,20 @@ namespace BMA.EHR.Application.Repositories.Commands .ThenInclude(x => x!.Organization) .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.PositionMaster) + .ThenInclude(x => x!.PositionPath) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.PositionMaster) + .ThenInclude(x => x!.PositionExecutive) .Where(x => x.OrganizationPosition!.Organization!.Id == ocId && x.OrganizationPosition!.PositionMaster!.IsDirector == true) - .Select(x => new KeyValueItemResponse + .Select(x => new OrganizationApproverResponse { Id = x.Profile!.Id, - Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}" + Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}", + PositionName = x.OrganizationPosition!.PositionMaster!.PositionExecutive != null ? + x.OrganizationPosition!.PositionMaster!.PositionExecutive!.Name + : + x.OrganizationPosition!.PositionMaster!.PositionPath == null ? "" : x.OrganizationPosition!.PositionMaster!.PositionPath!.Name }) .ToListAsync(); @@ -1302,19 +1310,27 @@ namespace BMA.EHR.Application.Repositories.Commands .ThenInclude(x => x!.Organization) .Include(x => x.OrganizationPosition) .ThenInclude(x => x!.PositionMaster) + .ThenInclude(x => x!.PositionPath) + .Include(x => x.OrganizationPosition) + .ThenInclude(x => x!.PositionMaster) + .ThenInclude(x => x!.PositionExecutive) .Where(x => x.OrganizationPosition!.Organization!.Id == oc.Parent.Id && x.OrganizationPosition!.PositionMaster!.IsDirector == true) - .Select(x => new KeyValueItemResponse + .Select(x => new OrganizationApproverResponse { Id = x.Profile!.Id, - Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}" + Name = $"{x.Profile!.Prefix!.Name}{x.Profile!.FirstName} {x.Profile!.LastName}", + PositionName = x.OrganizationPosition!.PositionMaster!.PositionExecutive != null ? + x.OrganizationPosition!.PositionMaster!.PositionExecutive!.Name + : + x.OrganizationPosition!.PositionMaster!.PositionPath == null ? "" : x.OrganizationPosition!.PositionMaster!.PositionPath!.Name }) .ToListAsync(); return parentProfilePosition; } else - return new List(); + return new List(); } } } diff --git a/BMA.EHR.Application/Responses/OrganizationApproverResponse.cs b/BMA.EHR.Application/Responses/OrganizationApproverResponse.cs new file mode 100644 index 00000000..e963c570 --- /dev/null +++ b/BMA.EHR.Application/Responses/OrganizationApproverResponse.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses +{ + public class OrganizationApproverResponse + { + public Guid Id { get; set; } = Guid.Empty; + + public string Name { get; set; } = string.Empty; + + public string PositionName { get; set; } = string.Empty; + } +} diff --git a/BMA.EHR.Command.Service/appsettings.json b/BMA.EHR.Command.Service/appsettings.json index c8cd1ab9..ddc81996 100644 --- a/BMA.EHR.Command.Service/appsettings.json +++ b/BMA.EHR.Command.Service/appsettings.json @@ -18,7 +18,7 @@ }, "Jwt": { "Key": "HP-FnQMUj9msHMSD3T9HtdEnphAKoCJLEl85CIqROFI", - "Issuer": "https://identity.frappet.com/realms/bma-ehr" + "Issuer": "https://id.frappet.synology.me/realms/bma-ehr" }, "EPPlus": { "ExcelPackage": { diff --git a/BMA.EHR.Command.Service/wwwroot/keycloak.json b/BMA.EHR.Command.Service/wwwroot/keycloak.json index 9eba3b39..a023eb38 100644 --- a/BMA.EHR.Command.Service/wwwroot/keycloak.json +++ b/BMA.EHR.Command.Service/wwwroot/keycloak.json @@ -1,6 +1,6 @@ { "realm": "bma-ehr", - "auth-server-url": "https://identity.frappet.com", + "auth-server-url": "https://id.frappet.synology.me", "ssl-required": "external", "resource": "bma-ehr", "public-client": true