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

Fix/submission emails #2405

Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,14 @@ const stubEverything = () => {
.returns({ toArray: () => subscriptionsToIncidentUpdates });
}

const incidentIds = pendingNotificationsToPromotedIncidents.map(
(pendingNotification) => pendingNotification.incident_id
);

stub
.withArgs({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: { $in: incidentIds },
})
.as(`subscriptions.find("${SUBSCRIPTION_TYPE.submissionPromoted}")`)
.returns({ toArray: () => subscriptionsToPromotedIncidents });
Expand Down Expand Up @@ -450,6 +455,7 @@ describe('Functions', () => {

expect(subscriptionsCollection.find.getCall(5).args[0]).to.deep.equal({
type: SUBSCRIPTION_TYPE.submissionPromoted,
incident_id: { $in: [217] },
});

for (const subscription of subscriptionsToPromotedIncidents) {
Expand All @@ -465,8 +471,6 @@ describe('Functions', () => {
incident_id: pendingNotification.incident_id,
});

console.log('subscriptionsToPromotedIncidents', global.context.functions);

const userIds = subscriptionsToPromotedIncidents.map((subscription) => subscription.userId);

const incident = incidents.find((i) => i.incident_id == pendingNotification.incident_id);
Expand Down
1 change: 1 addition & 0 deletions site/gatsby-site/src/templates/citeTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ function CiteTemplate({
reportCount: sortedReports.length,
incidentDate: incident.date,
editors: incident.editors
.filter((editor) => editor && editor.first_name && editor.last_name)
.map(({ first_name, last_name }) => `${first_name} ${last_name}`)
.join(', '),
}}
Expand Down
10 changes: 8 additions & 2 deletions site/realm/functions/processNotifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getRecipients = async (userIds) => {
for (const userId of userIds) {
const userResponse = await context.functions.execute('getUser', { userId });

if (userResponse.email) {
if (userResponse?.email) {
recipients.push({
email: userResponse.email,
userId,
Expand Down Expand Up @@ -262,13 +262,19 @@ exports = async function () {

// Notifications to New Promotions
try {

// Finds all pending notifications to New Promotions
const pendingNotificationsToNewPromotions = await notificationsCollection.find({ processed: false, type: 'submission-promoted' }).toArray();

// Gets all incident ids from pending notifications to New Promotions
const pendingNotificationsIncidentIds = pendingNotificationsToNewPromotions.map((notification) => notification.incident_id);

if (pendingNotificationsToNewPromotions.length > 0) {

result += pendingNotificationsToNewPromotions.length;

const subscriptionsToNewPromotions = await subscriptionsCollection.find({ type: 'submission-promoted' }).toArray();
// Finds all subscriptions to New Promotions for those new incidents
const subscriptionsToNewPromotions = await subscriptionsCollection.find({ type: 'submission-promoted', incident_id: { $in: pendingNotificationsIncidentIds } }).toArray();

// Process subscriptions to New Incidents
if (subscriptionsToNewPromotions.length > 0) {
Expand Down