Skip to content

Commit

Permalink
Filter to PRD departments and also send to delegated responsible
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathanio123 committed Aug 20, 2024
1 parent 41ee148 commit cddb878
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public async Task RunAsync(
if (!selectedDepartments.Any())
throw new Exception("No departments found.");

// TODO: Retrieving resource-owners wil be refactored later
// TODO: Retrieving resource-owners wil be refactored later to be more optimized
// But this will do for the first iteration
var resourceOwners = new List<LineOrgPerson>();
foreach (var orgUnitsChunk in selectedDepartments.Chunk(10))
{
Expand Down
24 changes: 19 additions & 5 deletions src/Fusion.Summary.Functions/Functions/WeeklyReportSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,28 @@ namespace Fusion.Summary.Functions.Functions;
public class WeeklyReportSender
{
private readonly ISummaryApiClient summaryApiClient;
private readonly IResourcesApiClient resourcesApiClient;
private readonly INotificationApiClient notificationApiClient;
private readonly ILogger<WeeklyReportSender> logger;
private readonly IConfiguration configuration;


public WeeklyReportSender(ISummaryApiClient summaryApiClient, INotificationApiClient notificationApiClient,
ILogger<WeeklyReportSender> logger, IConfiguration configuration)
ILogger<WeeklyReportSender> logger, IConfiguration configuration, IResourcesApiClient resourcesApiClient)
{
this.summaryApiClient = summaryApiClient;
this.notificationApiClient = notificationApiClient;
this.logger = logger;
this.configuration = configuration;
this.resourcesApiClient = resourcesApiClient;
}

[FunctionName("weekly-report-sender")]
public async Task RunAsync([TimerTrigger("0 0 8 * * 1", RunOnStartup = false)] TimerInfo timerInfo)
{
var departments = await summaryApiClient.GetDepartmentsAsync();
var departments =
(await summaryApiClient.GetDepartmentsAsync())?
.Where(d => d.FullDepartmentName!.Contains("PRD"));

if (departments is null)
{
Expand Down Expand Up @@ -70,7 +74,18 @@ await Parallel.ForEachAsync(departments, options, async (department, ct) =>
throw;
}

await notificationApiClient.SendNotification(notification, department.ResourceOwnerAzureUniqueId);
var reportReceivers =
(await resourcesApiClient.GetDelegatedResponsibleForDepartment(department.DepartmentSapId))
.Select(d => Guid.Parse(d.DelegatedResponsible.AzureUniquePersonId))
.Concat(new[] { department.ResourceOwnerAzureUniqueId })
.Distinct();

foreach (var azureId in reportReceivers)
{
var result = await notificationApiClient.SendNotification(notification, azureId);
if (!result)
logger.LogError("Failed to send notification to user with AzureId {AzureId} | Report {@ReportId}", azureId, summaryReport);
}
});
}

Expand Down Expand Up @@ -172,5 +187,4 @@ private string GetPortalUri()
portalUri += "/";
return portalUri;
}
}

}

0 comments on commit cddb878

Please sign in to comment.