add api add commander and approver ด้วย และเพิ่มประเภทของผู้อนุมัติ
This commit is contained in:
parent
193cffa7c4
commit
ddc3d268be
8 changed files with 1620 additions and 48 deletions
|
|
@ -113,6 +113,57 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
|
||||
#region " Methods "
|
||||
|
||||
/// <summary>
|
||||
/// เพิ่มรายชิื่อผู้อนุมัติ หรือ ผู้บังคับบัญชา
|
||||
/// </summary>
|
||||
/// <returns>
|
||||
/// </returns>
|
||||
/// <response code="200">เมื่อทำรายการสำเร็จ</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPost("officer/add-approver/{type}/{id:guid}")]
|
||||
[ProducesResponseType(StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<ActionResult<ResponseObject>> AddApprover(string type, Guid id, [FromBody] List<LeaveRequestApproverDto> req)
|
||||
{
|
||||
try
|
||||
{
|
||||
var leaveReq = await _leaveRequestRepository.GetByIdAsync(id);
|
||||
if (leaveReq == null)
|
||||
{
|
||||
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
|
||||
}
|
||||
|
||||
var delete = leaveReq.Approvers.RemoveAll(x => x.ApproveType == type.Trim().ToUpper());
|
||||
|
||||
foreach (var r in req)
|
||||
{
|
||||
leaveReq.Approvers.Add(new LeaveRequestApprover
|
||||
{
|
||||
Seq = r.Seq,
|
||||
Prefix = r.Prefix,
|
||||
FirstName = r.FirstName,
|
||||
LastName = r.LastName,
|
||||
PositionName = r.PositionName,
|
||||
ProfileId = r.ProfileId,
|
||||
KeycloakId = r.KeycloakId,
|
||||
ApproveStatus = "PENDING",
|
||||
ApproveType = type.Trim().ToUpper()
|
||||
});
|
||||
}
|
||||
|
||||
await _leaveRequestRepository.UpdateAsync(leaveReq);
|
||||
|
||||
return Success();
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return Error(ex);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LV2_001 - สร้างคำขอการลา (USER)
|
||||
/// </summary>
|
||||
|
|
@ -370,30 +421,30 @@ namespace BMA.EHR.Leave.Service.Controllers
|
|||
leaveRequest.PositionLevelName = profile.PosLevel == null ? "" : profile.PosLevel;
|
||||
leaveRequest.OrganizationName = userOc;
|
||||
|
||||
if (req.Approvers != null && req.Approvers != "")
|
||||
{
|
||||
//var jsonString = System.Text.Json.JsonSerializer.Deserialize<string>(req.Approvers ?? "");
|
||||
//var fixedJson = req.Approvers.Replace("\\\"", "\"");
|
||||
var approvers = JsonConvert.DeserializeObject<List<LeaveRequestApproverDto>>(req.Approvers);
|
||||
if (approver != null)
|
||||
{
|
||||
foreach (var r in approvers!)
|
||||
{
|
||||
leaveRequest.Approvers.Add(new LeaveRequestApprover
|
||||
{
|
||||
Seq = r.Seq,
|
||||
Prefix = r.Prefix,
|
||||
FirstName = r.FirstName,
|
||||
LastName = r.LastName,
|
||||
PositionName = r.PositionName,
|
||||
ProfileId = r.ProfileId,
|
||||
KeycloakId = r.KeycloakId,
|
||||
ApproveStatus = "PENDING",
|
||||
});
|
||||
}
|
||||
}
|
||||
//if (req.Approvers != null && req.Approvers != "")
|
||||
//{
|
||||
// //var jsonString = System.Text.Json.JsonSerializer.Deserialize<string>(req.Approvers ?? "");
|
||||
// //var fixedJson = req.Approvers.Replace("\\\"", "\"");
|
||||
// var approvers = JsonConvert.DeserializeObject<List<LeaveRequestApproverDto>>(req.Approvers);
|
||||
// if (approver != null)
|
||||
// {
|
||||
// foreach (var r in approvers!)
|
||||
// {
|
||||
// leaveRequest.Approvers.Add(new LeaveRequestApprover
|
||||
// {
|
||||
// Seq = r.Seq,
|
||||
// Prefix = r.Prefix,
|
||||
// FirstName = r.FirstName,
|
||||
// LastName = r.LastName,
|
||||
// PositionName = r.PositionName,
|
||||
// ProfileId = r.ProfileId,
|
||||
// KeycloakId = r.KeycloakId,
|
||||
// ApproveStatus = "PENDING",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
|
||||
}
|
||||
//}
|
||||
|
||||
|
||||
// save to database
|
||||
|
|
|
|||
|
|
@ -102,31 +102,7 @@ namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
|||
public DateTime? CoupleDayEndDateHistory { get; set; }
|
||||
|
||||
public string? CoupleDaySumTotalHistory { get; set; }
|
||||
|
||||
public string? Approvers { get; set; } = string.Empty;
|
||||
}
|
||||
|
||||
public class LeaveRequestApproverDto
|
||||
{
|
||||
[JsonProperty("seq")]
|
||||
public int Seq { get; set; } = 0;
|
||||
|
||||
[JsonProperty("prefix")]
|
||||
public string Prefix { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("firstName")]
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("lastName")]
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("positionName")]
|
||||
public string PositionName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("profileId")]
|
||||
public Guid ProfileId { get; set; } = Guid.Empty;
|
||||
|
||||
[JsonProperty("keycloakId")]
|
||||
public Guid KeycloakId { get; set; } = Guid.Empty;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
28
BMA.EHR.Leave/DTOs/LeaveRequest/LeaveRequestApproverDto.cs
Normal file
28
BMA.EHR.Leave/DTOs/LeaveRequest/LeaveRequestApproverDto.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using Newtonsoft.Json;
|
||||
|
||||
namespace BMA.EHR.Leave.Service.DTOs.LeaveRequest
|
||||
{
|
||||
public class LeaveRequestApproverDto
|
||||
{
|
||||
[JsonProperty("seq")]
|
||||
public int Seq { get; set; } = 0;
|
||||
|
||||
[JsonProperty("prefix")]
|
||||
public string Prefix { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("firstName")]
|
||||
public string FirstName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("lastName")]
|
||||
public string LastName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("positionName")]
|
||||
public string PositionName { get; set; } = string.Empty;
|
||||
|
||||
[JsonProperty("profileId")]
|
||||
public Guid ProfileId { get; set; } = Guid.Empty;
|
||||
|
||||
[JsonProperty("keycloakId")]
|
||||
public Guid KeycloakId { get; set; } = Guid.Empty;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue