แก้กรองตามสิทธิ์ #2104

This commit is contained in:
harid 2025-12-08 12:12:04 +07:00
parent 7778f6cccd
commit 08fb06ca84
2 changed files with 71 additions and 2 deletions

View file

@ -273,6 +273,46 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests
return data;
}
public async Task<List<LeaveRequest>> GetLeaveRequestByYearForAdminAsync(int year, string role, string? nodeId, int? node)
{
var rawData = await _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()
.Include(x => x.Type)
.Where(x => x.LeaveStartDate.Year == year)
.Where(x => x.LeaveStatus != "REJECT" && x.LeaveStatus != "DELETE")
.ToListAsync();
if (role == "OWNER")
{
node = null;
}
if (role == "OWNER" || role == "CHILD")
{
rawData = rawData
.Where(x => node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : (node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) : (node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) : (node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) : (node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) : (node == null ? true : true)))))).ToList();
}
else if (role == "ROOT")
{
rawData = rawData
.Where(x => x.RootDnaId == Guid.Parse(nodeId!)).ToList();
}
else if (role == "PARENT")
{
rawData = rawData
.Where(x => x.RootDnaId == Guid.Parse(nodeId!) && x.Child1DnaId != null).ToList();
}
else if (role == "NORMAL")
{
rawData = rawData
.Where(x =>
node == 0 ? x.RootDnaId == Guid.Parse(nodeId!) && x.Child1DnaId == null :
node == 1 ? x.Child1DnaId == Guid.Parse(nodeId!) && x.Child2DnaId == null :
node == 2 ? x.Child2DnaId == Guid.Parse(nodeId!) && x.Child3DnaId == null :
node == 3 ? x.Child3DnaId == Guid.Parse(nodeId!) && x.Child4DnaId == null :
node == 4 ? x.Child4DnaId == Guid.Parse(nodeId!) : true).ToList();
}
return rawData;
}
public async Task<List<LeaveRequest>> GetLeaveRequestByUserIdAsync(Guid keycloakUserId, int year, Guid type, string status)
{
var rawData = _dbContext.Set<LeaveRequest>().AsQueryable().AsNoTracking()