feature/IO-3096-GlobalNotifications - Checkpoint, fixed some email bugs in other files, consolidated the GetEndpoints on the backend, moved the consolidation delays for queues to ENV vars
This commit is contained in:
@@ -7,7 +7,7 @@ const APP_CONSOLIDATION_DELAY_IN_MINS = (() => {
|
||||
return isNaN(parsedValue) ? 1 : Math.max(1, parsedValue); // Default to 1, ensure at least 1
|
||||
})();
|
||||
|
||||
// Base time-related constant (in milliseconds)
|
||||
// Base time-related constant (in milliseconds) / DO NOT TOUCH
|
||||
const APP_CONSOLIDATION_DELAY = APP_CONSOLIDATION_DELAY_IN_MINS * 60000; // 1 minute (base timeout)
|
||||
|
||||
// Derived time-related constants based on APP_CONSOLIDATION_DELAY / DO NOT TOUCH, these are pegged to APP_CONSOLIDATION_DELAY
|
||||
|
||||
@@ -9,7 +9,7 @@ const EMAIL_CONSOLIDATION_DELAY_IN_MINS = (() => {
|
||||
return isNaN(parsedValue) ? 1 : Math.max(1, parsedValue); // Default to 1, ensure at least 1
|
||||
})();
|
||||
|
||||
// Base time-related constant (in milliseconds)
|
||||
// Base time-related constant (in milliseconds) / DO NOT TOUCH
|
||||
const EMAIL_CONSOLIDATION_DELAY = EMAIL_CONSOLIDATION_DELAY_IN_MINS * 60000; // 1 minute (base timeout)
|
||||
|
||||
// Derived time-related constants based on EMAIL_CONSOLIDATION_DELAY / DO NOT TOUCH, these are pegged to EMAIL_CONSOLIDATION_DELAY
|
||||
@@ -58,13 +58,13 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
||||
|
||||
const redisKeyPrefix = `email:notifications:${jobId}`;
|
||||
for (const recipient of recipients) {
|
||||
const { user } = recipient;
|
||||
const { user, firstName, lastName } = recipient;
|
||||
const userKey = `${redisKeyPrefix}:${user}`;
|
||||
await pubClient.rpush(userKey, body);
|
||||
await pubClient.expire(userKey, NOTIFICATION_EXPIRATION / 1000); // Set expiration
|
||||
const detailsKey = `email:recipientDetails:${jobId}:${user}`;
|
||||
await pubClient.hsetnx(detailsKey, "firstName", recipient.firstName || "");
|
||||
await pubClient.hsetnx(detailsKey, "lastName", recipient.lastName || "");
|
||||
await pubClient.hsetnx(detailsKey, "firstName", firstName || "");
|
||||
await pubClient.hsetnx(detailsKey, "lastName", lastName || "");
|
||||
await pubClient.expire(detailsKey, NOTIFICATION_EXPIRATION / 1000); // Set expiration
|
||||
await pubClient.sadd(`email:recipients:${jobId}`, user);
|
||||
logger.logger.debug(`Stored message for ${user} under ${userKey}: ${body}`);
|
||||
@@ -116,10 +116,11 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
||||
if (messages.length > 0) {
|
||||
const details = await pubClient.hgetall(detailsKey);
|
||||
const firstName = details.firstName || "User";
|
||||
const subject = `Updates for job ${jobRoNumber} at ${bodyShopName}`;
|
||||
const multipleUpdateString = messages.length > 1 ? "Updates" : "Update";
|
||||
const subject = `${multipleUpdateString} for job ${jobRoNumber} at ${bodyShopName}`;
|
||||
// Use the template instead of inline HTML
|
||||
const emailBody = generateEmailTemplate({
|
||||
header: `Updates for Job ${jobRoNumber}`,
|
||||
header: `${multipleUpdateString} for Job ${jobRoNumber}`,
|
||||
subHeader: `Dear ${firstName},`,
|
||||
body: `
|
||||
<p>There have been updates to job ${jobRoNumber} at ${bodyShopName}:</p><br/>
|
||||
|
||||
Reference in New Issue
Block a user