API ลบรายการเฉพาะสิทธิ์ OWNER #1586
This commit is contained in:
parent
3f98e07419
commit
dc5ac329e2
7 changed files with 268 additions and 2 deletions
|
|
@ -1811,6 +1811,47 @@ namespace BMA.EHR.Retirement.Service.Controllers
|
|||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// API ลบรายการลาออก (ADMIN)
|
||||
/// </summary>
|
||||
/// <param name="id">Id ลาออก</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("admin/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteForAdminAsync(Guid id)
|
||||
{
|
||||
var jsonData = await _permission.GetPermissionWithActingAPIAsync("DELETE", "SYS_RESIGN");
|
||||
if (jsonData!.status != 200)
|
||||
{
|
||||
return Error(jsonData.message, StatusCodes.Status403Forbidden);
|
||||
}
|
||||
// ตรวจสอบว่า role ต้องเป็น OWNER เท่านั้น
|
||||
if (jsonData.result.privilege != "OWNER")
|
||||
{
|
||||
return Error("ไม่มีสิทธิ์ในการลบรายการลาออก", StatusCodes.Status403Forbidden);
|
||||
}
|
||||
var deleted = await _context.RetirementResigns.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (deleted == null)
|
||||
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
||||
|
||||
// ห้ามลบเฉพาะสถานะ REPORT, WAITING, DONE, CANCELING, CANCEL
|
||||
if (new[] { "REPORT", "WAITING", "DONE", "CANCELING", "CANCEL" }.Contains(deleted.Status))
|
||||
{
|
||||
return Error("ไม่สามารถลบรายการลาออกสถานะนี้ได้");
|
||||
}
|
||||
|
||||
deleted.Status = "DELETE";
|
||||
deleted.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
deleted.LastUpdateUserId = UserId ?? "";
|
||||
deleted.LastUpdatedAt = DateTime.Now;
|
||||
await _context.SaveChangesAsync();
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// อนุมัติคำลาออก
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue