Show scoped military retention deadlines
This commit is contained in:
1 parent
9c8c504d98
commit
78b7af8ccc
5 files changed
+78
-5
No files matched your search
@@ -112,6 +112,39 @@ public sealed class StudentStatusChangesController(
|
||||
.ToListAsync(token));
|
||||
}
|
||||
|
||||
[HttpGet("discharge-deadlines")]
|
||||
[Authorize(Roles = SystemRoles.Counselor + "," + SystemRoles.CollegeAdmin + "," + SystemRoles.AcademicAdmin + "," + SystemRoles.SuperAdmin)]
|
||||
public async Task<ActionResult> GetDischargeDeadlines(CancellationToken token)
|
||||
{
|
||||
var students = ScopedStudents().Where(x => !x.IsArchived && x.Status == StudentStatus.Retained);
|
||||
var reports = await db.StudentMilitaryDischargeReports.AsNoTracking()
|
||||
.Where(report => students.Any(student => student.Id == report.StudentId) &&
|
||||
db.StudentStatusChanges.Where(change => change.StudentId == report.StudentId &&
|
||||
change.Type == StudentStatusChangeType.Enlistment && change.State == StudentStatusChangeState.Approved)
|
||||
.OrderByDescending(change => change.ApprovedAt).ThenByDescending(change => change.Id)
|
||||
.Select(change => change.Id).FirstOrDefault() == report.EnlistmentChangeId &&
|
||||
db.StudentMilitaryDischargeReports.Where(other => other.StudentId == report.StudentId &&
|
||||
other.EnlistmentChangeId == report.EnlistmentChangeId)
|
||||
.OrderByDescending(other => other.ReportedAt).ThenByDescending(other => other.Id)
|
||||
.Select(other => other.Id).FirstOrDefault() == report.Id)
|
||||
.OrderBy(report => report.DischargeDate).ThenBy(report => report.StudentId)
|
||||
.Take(100)
|
||||
.Select(report => new
|
||||
{
|
||||
report.StudentId, report.DischargeDate, report.ReportedAt,
|
||||
StudentNumber = db.Students.Where(student => student.Id == report.StudentId).Select(student => student.StudentNumber).FirstOrDefault(),
|
||||
StudentName = db.Students.Where(student => student.Id == report.StudentId).Select(student => student.Name).FirstOrDefault(),
|
||||
ClassName = db.Students.Where(student => student.Id == report.StudentId).Select(student => student.AdministrativeClass!.Name).FirstOrDefault()
|
||||
}).ToListAsync(token);
|
||||
var today = DateOnly.FromDateTime(DateTime.UtcNow);
|
||||
return Ok(reports.Select(report => new
|
||||
{
|
||||
report.StudentId, report.StudentNumber, report.StudentName, report.ClassName, report.DischargeDate,
|
||||
report.ReportedAt, RetainedUntil = report.DischargeDate.AddYears(2),
|
||||
DaysRemaining = report.DischargeDate.AddYears(2).DayNumber - today.DayNumber
|
||||
}));
|
||||
}
|
||||
|
||||
[HttpGet("students/{studentId:guid}/options")]
|
||||
[Authorize(Roles = SystemRoles.Counselor + "," + SystemRoles.CollegeAdmin + "," + SystemRoles.AcademicAdmin + "," + SystemRoles.SuperAdmin)]
|
||||
public async Task<ActionResult> GetStudentOptions(Guid studentId, CancellationToken token)
|
||||
|
||||
Reference in new issue
Block a user