Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync with master #189

Merged
merged 19 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion api/controllers/usermanagement/SheriffController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,17 @@ public class SheriffController : UserController
private ShiftService ShiftService { get; }
private DutyRosterService DutyRosterService { get; }
private SheriffDbContext Db { get; }
private TrainingService TrainingService { get; }

// ReSharper disable once InconsistentNaming
private readonly long _uploadPhotoSizeLimitKB;

public SheriffController(SheriffService sheriffService, DutyRosterService dutyRosterService, ShiftService shiftService, UserService userUserService, IConfiguration configuration, SheriffDbContext db) : base(userUserService)
public SheriffController(SheriffService sheriffService, DutyRosterService dutyRosterService, ShiftService shiftService, UserService userUserService,TrainingService trainingService, IConfiguration configuration, SheriffDbContext db) : base(userUserService)
{
SheriffService = sheriffService;
ShiftService = shiftService;
DutyRosterService = dutyRosterService;
TrainingService = trainingService;
Db = db;
_uploadPhotoSizeLimitKB = Convert.ToInt32(configuration.GetNonEmptyValue("UploadPhotoSizeLimitKB"));
}
Expand Down Expand Up @@ -155,6 +157,15 @@ public async Task<ActionResult<SheriffDto>> UploadPhoto(Guid? id, string badgeNu
return Ok(sheriff.Adapt<SheriffDto>());
}

[HttpPut]
[Route("updateExcused")]
[PermissionClaimAuthorize(perm: Permission.GenerateReports)]
public async Task<ActionResult<SheriffDto>> UpdateExcused(Sheriff excusedSheriff)
{
var sheriff = await SheriffService.UpdateSheriffExcused(excusedSheriff);
return Ok(sheriff.Adapt<SheriffDto>());
}

#endregion Sheriff

#region SheriffAwayLocation
Expand Down Expand Up @@ -268,6 +279,28 @@ public async Task<ActionResult> RemoveSheriffLeave(int id, string expiryReason)

#endregion SheriffLeave

#region SheriffTrainingReports

[HttpPost]
[Route("training/reports")]
[PermissionClaimAuthorize(perm: Permission.GenerateReports)]
public async Task<ActionResult<TrainingReportDto>> GetSheriffsTrainingReports(TrainingReportSearchDto trainingReportSearch)
{
var sheriffs = await TrainingService.GetSheriffsTrainingReports(trainingReportSearch);
return Ok(sheriffs.Adapt<List<TrainingReportDto>>());
}

[HttpGet]
[Route("training/adjust-expiry")]
[PermissionClaimAuthorize(perm: Permission.AdjustTrainingExpiry)]
public async Task<ActionResult> TrainingExpiryAdjustment()
{
await TrainingService.TrainingExpiryAdjustment();
return Ok(new { result = "success"});
}

#endregion SheriffTrainingReports

#region SheriffTraining

[HttpGet]
Expand Down
24 changes: 20 additions & 4 deletions api/cronjobs/TrainingNotification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,14 @@ public async void ProcessTrainings()
Logger.LogInformation(training.Sheriff.Email);

if(training.TrainingCertificationExpiry < noticeDate){
var emailBody = GetEmailBody(training);

bool rotatingTraining = TrainingService.IsRotatingTraining(training.TrainingType);
var emailBody = rotatingTraining? GetEmailRotatingBody(training) : GetEmailEndOfYearBody(training);
var emailTitle = rotatingTraining? "Training Expiry Notice" : "Training Requalification Notice";

var emailSent = await ChesEmailService.SendEmail(
emailBody,
"Training Expiry Notice",
emailTitle,
training.Sheriff.Email
);
if(emailSent)
Expand All @@ -52,17 +56,29 @@ public async void ProcessTrainings()
Logger.LogInformation("CronJob Done");
}

public string GetEmailBody(SheriffTraining training)
public string GetEmailRotatingBody(SheriffTraining training)
{
var expiryDate = training.TrainingCertificationExpiry.Value.ToString("MMMM dd, yyyy");
var emailBody =
$"Dear {training.Sheriff.FirstName} {training.Sheriff.LastName}, \n"+
$"Dear {training.Sheriff.FirstName} {training.Sheriff.LastName}, \n\n"+
$"Your \'{training.TrainingType.Code}\' certification will expire on \'{expiryDate}\'. \n"+
"Please ensure your certification is renewed before this date.";

return emailBody;
}

public string GetEmailEndOfYearBody(SheriffTraining training)
{
var expiryYear = training.TrainingCertificationExpiry.Value.AddDays(-1).AddYears(1).ToString("yyyy");
var emailBody =
$"Dear {training.Sheriff.FirstName} {training.Sheriff.LastName}, \n\n"+
$"Your \'{training.TrainingType.Code}\' certification will require renewal for the calendar year \'{expiryYear}\'. \n"+
$"Please ensure you renew your certification between January 1st and December 31, {expiryYear}. \n\n" +
"It is recommended to schedule training early in the year to ensure end of year compliance.";

return emailBody;
}

public Task Execute(IJobExecutionContext context)
{
Logger.LogInformation("___Running CronJob___");
Expand Down
5 changes: 5 additions & 0 deletions api/models/dto/AddLookupCodeDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ public class AddLookupCodeDto
public DateTimeOffset? EffectiveDate { get; set; }
public DateTimeOffset? ExpiryDate { get; set; }
public int? LocationId { get; set; }
public bool? Mandatory { get; set; }
public bool? Rotating { get; set; }
public int? ValidityPeriod { get; set; }
public string? Category { get; set; }
public int? AdvanceNotice { get; set; }
public AddLookupSortOrderDto SortOrderForLocation { get; set; }
}
}
16 changes: 16 additions & 0 deletions api/models/dto/TrainingReportDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;

namespace SS.Api.models.dto
{
public class TrainingReportDto
{
public string name { get; set; }
public string trainingType { get; set; }
public DateTimeOffset? end { get; set; }
public DateTimeOffset? expiryDate { get; set; }
public bool excluded { get; set; }
public Guid sheriffId { get; set; }
public string status { get; set; }
public string _rowVariant { get; set; }
}
}
14 changes: 14 additions & 0 deletions api/models/dto/TrainingReportSearchDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;


namespace SS.Api.models.dto
{
public class TrainingReportSearchDto
{
public int? regionId { get; set; }
public int? locationId { get; set; }
public int? reportSubtypeId { get; set; }
public DateTimeOffset? startDate { get; set; }
public DateTimeOffset? endDate { get; set; }
}
}
1 change: 1 addition & 0 deletions api/models/dto/generated/LookupCodeDto.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public partial class LookupCodeDto
public int ValidityPeriod { get; set; }
public string Category { get; set; }
public int AdvanceNotice { get; set; }
public bool Rotating { get; set; }
public uint ConcurrencyToken { get; set; }
public LookupSortOrderDto SortOrderForLocation { get; set; }
}
Expand Down
1 change: 1 addition & 0 deletions api/models/dto/generated/SheriffDto.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public partial class SheriffDto
public List<SheriffTrainingDto> Training { get; set; }
public string PhotoUrl { get; set; }
public DateTimeOffset LastPhotoUpdate { get; set; }
public bool Excused { get; set; }
public Guid Id { get; set; }
public bool IsEnabled { get; set; }
public string FirstName { get; set; }
Expand Down
8 changes: 8 additions & 0 deletions api/models/types/TrainingStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace SS.Api.models.types
{
public class TrainingStatus
{
public string status;
public string rowType;
}
}
10 changes: 10 additions & 0 deletions api/models/types/TrainingStatusTypes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace SS.Api.models.types
{
public static class TrainingStatusTypes
{
public static readonly string danger = "Not Taken";
public static readonly string alert = "Expired";
public static readonly string warning = "Requalification";
public static readonly string notify = "Notified";
}
}
20 changes: 20 additions & 0 deletions api/services/ManageTypesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,26 @@ public async Task<List<LookupCode>> GetAll(LookupTypes? codeType, int? locationI
return lookupCodes;
}

public async Task<List<LookupCode>> GetAllForReports(int? id, LookupTypes? codeType, int? locationId, bool? mandatory, bool showExpired = false)
{
var lookupCodes = await Db.LookupCode.AsNoTracking()
.Include(lc => lc.SortOrder.Where(so => so.LocationId == locationId))
.Where(lc =>
(id == null || lc.Id == id) &&
(codeType == null || lc.Type == codeType) &&
(locationId == null || lc.LocationId == null || lc.LocationId == locationId) &&
(mandatory == null || lc.Mandatory == mandatory) &&
(showExpired || lc.ExpiryDate == null))
.OrderBy(a => (int)a.Type)
.ThenBy(a => a.SortOrder.FirstOrDefault().SortOrder)
.ThenBy(a => a.Id)
.ToListAsync();

lookupCodes.ForEach(lc => lc.SortOrderForLocation = lc.SortOrder.FirstOrDefault());

return lookupCodes;
}

public async Task<LookupCode> Find(int id) => await Db.LookupCode.AsNoTracking().FirstOrDefaultAsync(lc => lc.Id == id);

public async Task<LookupCode> Expire(int id)
Expand Down
9 changes: 9 additions & 0 deletions api/services/usermanagement/SheriffService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ public async Task<Sheriff> UpdateSheriffPhoto(Guid? id, string badgeNumber, byte
return savedSheriff;
}

public async Task<Sheriff> UpdateSheriffExcused(Sheriff sheriff)
{
var savedSheriff = await Db.Sheriff.FindAsync(sheriff.Id);
savedSheriff.ThrowBusinessExceptionIfNull($"No {nameof(Sheriff)} with Id: {sheriff.Id}");
savedSheriff.Excused = sheriff.Excused;
await Db.SaveChangesAsync();
return savedSheriff;
}

public async Task UpdateSheriffHomeLocation(Guid id, int locationId)
{
var savedSheriff = await Db.Sheriff.FindAsync(id);
Expand Down
Loading
Loading