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

Point Submission Reminder #341

Merged
merged 4 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 6 additions & 0 deletions src/dotnet/HQ.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@
Cron.Weekly(DayOfWeek.Monday, 12),
recurringJobOptions);

recurringJobManager.AddOrUpdate<PointServiceV1>(
nameof(PointServiceV1.BackgroundSendPointSubmissionReminderEmail),
(t) => t.BackgroundSendPointSubmissionReminderEmail(Period.Week, CancellationToken.None),
Cron.Weekly(DayOfWeek.Monday, 12),
recurringJobOptions);

// Friday morning
recurringJobManager.AddOrUpdate<HolidayServiceV1>(
nameof(HolidayServiceV1.BackgroundAutoGenerateHolidayTimeEntryV1),
Expand Down
21 changes: 21 additions & 0 deletions src/dotnet/HQ.Server/Services/EmailMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,5 +202,26 @@ public async Task SendRejectedTimeSubmissionReminderEmail(Guid staffId, DateOnly

await SendEmail(EmailMessage.Notification, model, staff.Email, "[HQ] Rejected Time Reminder", MailPriority.High, null, ct);
}
public async Task SendPointSubmissionReminderEmail(Guid staffId, DateOnly from, DateOnly to, CancellationToken ct)
{
var staff = await _context.Staff
.AsNoTracking()
.SingleOrDefaultAsync(t => t.Id == staffId, ct);

if (staff == null || String.IsNullOrEmpty(staff.Email))
{
return;
}

var model = new NotificationEmail()
{
Heading = "Planning Point Submission Reminder",
Message = $"You have unsubmitted planning points in HQ for this week. Please remember to submit for review by 12PM EST.",
rmaffitsancsoft marked this conversation as resolved.
Show resolved Hide resolved
ButtonLabel = "Open HQ",
ButtonUrl = _options.CurrentValue.WebUrl
};

await SendEmail(EmailMessage.Notification, model, staff.Email, "[HQ] Planning Point Submission Reminder", MailPriority.High, null, ct);
}
}
}
24 changes: 22 additions & 2 deletions src/dotnet/HQ.Server/Services/PointServiceV1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

using FluentResults;

using HQ.Abstractions;
using Hangfire;

using HQ.Abstractions;
using HQ.Abstractions.Enumerations;
using HQ.Abstractions.Points;
using HQ.Server.Data;
Expand All @@ -20,10 +21,12 @@ namespace HQ.Server.Services;
public class PointServiceV1
{
private readonly HQDbContext _context;
private readonly IBackgroundJobClient _backgroundJobClient;

public PointServiceV1(HQDbContext context)
public PointServiceV1(HQDbContext context, IBackgroundJobClient backgroundJobClient)
{
_context = context;
_backgroundJobClient = backgroundJobClient;
}
public async Task<Result<GetPointsV1.Response>> GetPointsV1(GetPointsV1.Request request, CancellationToken ct = default)
{
Expand Down Expand Up @@ -357,4 +360,21 @@ public async Task BackgroundAutoGenerateHolidayPlanningPointsV1(CancellationToke
};
}

public async Task BackgroundSendPointSubmissionReminderEmail(Period period, CancellationToken ct)
{
var startDate = DateOnly.FromDateTime(DateTime.UtcNow).GetPeriodStartDate(period);
var endDate = DateOnly.FromDateTime(DateTime.UtcNow).GetPeriodEndDate(period);
var points = _context.Points.Where(t => t.Date >= startDate && t.Date <= endDate);
var unsubmittedPoints = points.Where(t => !t.Completed);

var staffToNotify = await _context.Staff
.AsNoTracking()
.Where(t => t.EndDate == null && points.Where(x => x.StaffId == t.Id).Count() == 0 || unsubmittedPoints.Where(x => x.StaffId == t.Id).Count() > 0)
rmaffitsancsoft marked this conversation as resolved.
Show resolved Hide resolved
.ToListAsync(ct);

foreach (var staff in staffToNotify)
{
_backgroundJobClient.Enqueue<EmailMessageService>(t => t.SendPointSubmissionReminderEmail(staff.Id, startDate, endDate, CancellationToken.None));
}
}
}