Show recorded approval progress
This commit is contained in:
1 parent
88ef93022d
commit
75f1751629
6 files changed
+165
-1
No files matched your search
@@ -54,6 +54,68 @@ public sealed class ApprovalsController(
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpGet("progress/{type}/{id:guid}")]
|
||||
public async Task<ActionResult<ApprovalProgressResponse>> GetProgress(string type, Guid id, CancellationToken ct)
|
||||
{
|
||||
var current = scope.Current;
|
||||
var manager = current.IsInRole(SystemRoles.SuperAdmin) || current.IsInRole(SystemRoles.AcademicAdmin) || current.IsInRole(SystemRoles.CollegeAdmin);
|
||||
var userId = current.UserId;
|
||||
var steps = new List<ApprovalProgressStep>();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "CourseExemption":
|
||||
{
|
||||
var query = manager ? Scoped<CourseExemption>(x => x.Id == id) : db.CourseExemptions.AsNoTracking().Where(x => x.Id == id && x.Student!.UserId == userId);
|
||||
var item = await query.FirstOrDefaultAsync(ct);
|
||||
if (item is null) return NotFound();
|
||||
AddSingleApprovalSteps(steps, item.SubmittedAt, item.ReviewedAt, item.Status, item.ReviewComment);
|
||||
break;
|
||||
}
|
||||
case "DeferredExam":
|
||||
{
|
||||
var query = manager ? Scoped<DeferredExam>(x => x.Id == id) : db.DeferredExams.AsNoTracking().Where(x => x.Id == id && x.Student!.UserId == userId);
|
||||
var item = await query.FirstOrDefaultAsync(ct);
|
||||
if (item is null) return NotFound();
|
||||
AddSingleApprovalSteps(steps, item.SubmittedAt, item.ReviewedAt, item.Status, item.ReviewComment);
|
||||
break;
|
||||
}
|
||||
case "CourseSubstitution":
|
||||
{
|
||||
var query = manager ? Scoped<CourseSubstitution>(x => x.Id == id) : db.CourseSubstitutions.AsNoTracking().Where(x => x.Id == id && x.Student!.UserId == userId);
|
||||
var item = await query.FirstOrDefaultAsync(ct);
|
||||
if (item is null) return NotFound();
|
||||
AddSingleApprovalSteps(steps, item.SubmittedAt, item.ReviewedAt, item.Status, item.ReviewComment);
|
||||
break;
|
||||
}
|
||||
case "GradeModification":
|
||||
{
|
||||
var query = manager ? Scoped<GradeModification>(x => x.Id == id) : db.GradeModifications.AsNoTracking().Where(x => x.Id == id && x.ApplicantUserId == userId);
|
||||
var item = await query.FirstOrDefaultAsync(ct);
|
||||
if (item is null) return NotFound();
|
||||
steps.Add(new("submitted", item.SubmittedAt, item.Reason));
|
||||
if (item.CollegeReviewedAt is { } collegeTime)
|
||||
{
|
||||
var rejected = item.Status == GradeModificationStatus.Rejected && item.FinalReviewedAt is null;
|
||||
steps.Add(new(rejected ? "collegeRejected" : "collegeApproved", collegeTime, rejected ? item.ReviewComment : null));
|
||||
}
|
||||
if (item.FinalReviewedAt is { } finalTime)
|
||||
steps.Add(new(item.Status == GradeModificationStatus.Rejected ? "finalRejected" : "finalApproved", finalTime, item.ReviewComment));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
return NotFound();
|
||||
}
|
||||
return Ok(new ApprovalProgressResponse(type, id, steps));
|
||||
}
|
||||
|
||||
private static void AddSingleApprovalSteps(List<ApprovalProgressStep> steps, DateTime submittedAt, DateTime? reviewedAt, ApprovalStatus status, string? comment)
|
||||
{
|
||||
steps.Add(new("submitted", submittedAt, null));
|
||||
if (reviewedAt is { } time && status is ApprovalStatus.Approved or ApprovalStatus.Rejected)
|
||||
steps.Add(new(status == ApprovalStatus.Approved ? "approved" : "rejected", time, comment));
|
||||
}
|
||||
|
||||
// ═══════════════ Aggregated pending ═══════════════
|
||||
[HttpGet("pending")]
|
||||
[Authorize(Roles = Managers + "," + SystemRoles.Teacher + "," + SystemRoles.Counselor + "," + SystemRoles.DormitoryAdmin + "," + SystemRoles.StudentAffairsAdmin + "," + SystemRoles.Leader)]
|
||||
@@ -1023,6 +1085,8 @@ public sealed class ApprovalsController(
|
||||
public sealed record ApprovalItem(Guid Id, string Type, string Label, string Title, string Desc, DateTime Time, string College, string? Stage = null, Guid? SecondaryId = null);
|
||||
public sealed record ApprovalPendingResult(IReadOnlyCollection<ApprovalItem> Items, int Total, int Page, int PageSize, IReadOnlyDictionary<string, int> Counts);
|
||||
public sealed record ApprovalRouteSettingRequest([Required] string ReviewerRole);
|
||||
public sealed record ApprovalProgressStep(string Kind, DateTime Time, string? Comment);
|
||||
public sealed record ApprovalProgressResponse(string Type, Guid Id, IReadOnlyList<ApprovalProgressStep> Steps);
|
||||
|
||||
internal static class ApprovalOrderingExtensions
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user