IO-3096-GlobalNotifications - Correct time zone from footer in notification email
This commit is contained in:
@@ -20,6 +20,11 @@ const defaultFooter = () => {
|
|||||||
|
|
||||||
const now = () => moment().format("MM/DD/YYYY @ hh:mm a");
|
const now = () => moment().format("MM/DD/YYYY @ hh:mm a");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the email template
|
||||||
|
* @param strings
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
const generateEmailTemplate = (strings) => {
|
const generateEmailTemplate = (strings) => {
|
||||||
return (
|
return (
|
||||||
`
|
`
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const { InstanceEndpoints } = require("../../utils/instanceMgr");
|
|||||||
const { registerCleanupTask } = require("../../utils/cleanupManager");
|
const { registerCleanupTask } = require("../../utils/cleanupManager");
|
||||||
const getBullMQPrefix = require("../../utils/getBullMQPrefix");
|
const getBullMQPrefix = require("../../utils/getBullMQPrefix");
|
||||||
const devDebugLogger = require("../../utils/devDebugLogger");
|
const devDebugLogger = require("../../utils/devDebugLogger");
|
||||||
|
const moment = require("moment-timezone");
|
||||||
|
|
||||||
const EMAIL_CONSOLIDATION_DELAY_IN_MINS = (() => {
|
const EMAIL_CONSOLIDATION_DELAY_IN_MINS = (() => {
|
||||||
const envValue = process.env?.EMAIL_CONSOLIDATION_DELAY_IN_MINS;
|
const envValue = process.env?.EMAIL_CONSOLIDATION_DELAY_IN_MINS;
|
||||||
@@ -59,7 +60,7 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
|||||||
emailAddWorker = new Worker(
|
emailAddWorker = new Worker(
|
||||||
"emailAdd",
|
"emailAdd",
|
||||||
async (job) => {
|
async (job) => {
|
||||||
const { jobId, jobRoNumber, bodyShopName, body, recipients } = job.data;
|
const { jobId, jobRoNumber, bodyShopName, bodyShopTimezone, body, recipients } = job.data;
|
||||||
devDebugLogger(`Adding email notifications for jobId ${jobId}`);
|
devDebugLogger(`Adding email notifications for jobId ${jobId}`);
|
||||||
|
|
||||||
const redisKeyPrefix = `email:${devKey}:notifications:${jobId}`;
|
const redisKeyPrefix = `email:${devKey}:notifications:${jobId}`;
|
||||||
@@ -72,6 +73,7 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
|||||||
const detailsKey = `email:${devKey}:recipientDetails:${jobId}:${user}`;
|
const detailsKey = `email:${devKey}:recipientDetails:${jobId}:${user}`;
|
||||||
await pubClient.hsetnx(detailsKey, "firstName", firstName || "");
|
await pubClient.hsetnx(detailsKey, "firstName", firstName || "");
|
||||||
await pubClient.hsetnx(detailsKey, "lastName", lastName || "");
|
await pubClient.hsetnx(detailsKey, "lastName", lastName || "");
|
||||||
|
await pubClient.hsetnx(detailsKey, "bodyShopTimezone", bodyShopTimezone);
|
||||||
await pubClient.expire(detailsKey, NOTIFICATION_EXPIRATION / 1000);
|
await pubClient.expire(detailsKey, NOTIFICATION_EXPIRATION / 1000);
|
||||||
await pubClient.sadd(`email:${devKey}:recipients:${jobId}`, user);
|
await pubClient.sadd(`email:${devKey}:recipients:${jobId}`, user);
|
||||||
devDebugLogger(`Stored message for ${user} under ${userKey}: ${body}`);
|
devDebugLogger(`Stored message for ${user} under ${userKey}: ${body}`);
|
||||||
@@ -82,7 +84,7 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
|||||||
if (flagSet) {
|
if (flagSet) {
|
||||||
await emailConsolidateQueue.add(
|
await emailConsolidateQueue.add(
|
||||||
"consolidate-emails",
|
"consolidate-emails",
|
||||||
{ jobId, jobRoNumber, bodyShopName },
|
{ jobId, jobRoNumber, bodyShopName, bodyShopTimezone },
|
||||||
{
|
{
|
||||||
jobId: `consolidate:${jobId}`,
|
jobId: `consolidate:${jobId}`,
|
||||||
delay: EMAIL_CONSOLIDATION_DELAY,
|
delay: EMAIL_CONSOLIDATION_DELAY,
|
||||||
@@ -125,9 +127,11 @@ const loadEmailQueue = async ({ pubClient, logger }) => {
|
|||||||
const firstName = details.firstName || "User";
|
const firstName = details.firstName || "User";
|
||||||
const multipleUpdateString = messages.length > 1 ? "Updates" : "Update";
|
const multipleUpdateString = messages.length > 1 ? "Updates" : "Update";
|
||||||
const subject = `${multipleUpdateString} for job ${jobRoNumber || "N/A"} at ${bodyShopName}`;
|
const subject = `${multipleUpdateString} for job ${jobRoNumber || "N/A"} at ${bodyShopName}`;
|
||||||
|
const timezone = moment.tz.zone(details?.bodyShopTimezone) ? details.bodyShopTimezone : "UTC";
|
||||||
const emailBody = generateEmailTemplate({
|
const emailBody = generateEmailTemplate({
|
||||||
header: `${multipleUpdateString} for Job ${jobRoNumber || "N/A"}`,
|
header: `${multipleUpdateString} for Job ${jobRoNumber || "N/A"}`,
|
||||||
subHeader: `Dear ${firstName},`,
|
subHeader: `Dear ${firstName},`,
|
||||||
|
dateLine: moment().tz(timezone).format("MM/DD/YYYY hh:mm a"),
|
||||||
body: `
|
body: `
|
||||||
<p>There have been updates to job ${jobRoNumber || "N/A"} at ${bodyShopName}:</p><br/>
|
<p>There have been updates to job ${jobRoNumber || "N/A"} at ${bodyShopName}:</p><br/>
|
||||||
<ul>
|
<ul>
|
||||||
@@ -226,10 +230,10 @@ const dispatchEmailsToQueue = async ({ emailsToDispatch, logger }) => {
|
|||||||
const emailAddQueue = getQueue();
|
const emailAddQueue = getQueue();
|
||||||
|
|
||||||
for (const email of emailsToDispatch) {
|
for (const email of emailsToDispatch) {
|
||||||
const { jobId, jobRoNumber, bodyShopName, body, recipients } = email;
|
const { jobId, jobRoNumber, bodyShopName, bodyShopTimezone, body, recipients } = email;
|
||||||
|
|
||||||
if (!jobId || !jobRoNumber || !bodyShopName || !body || !recipients.length) {
|
if (!jobId || !jobRoNumber || !bodyShopName || !body || !recipients.length) {
|
||||||
logger.logger.warn(
|
devDebugLogger(
|
||||||
`Skipping email dispatch for jobId ${jobId} due to missing data: ` +
|
`Skipping email dispatch for jobId ${jobId} due to missing data: ` +
|
||||||
`jobRoNumber=${jobRoNumber || "N/A"}, bodyShopName=${bodyShopName}, body=${body}, recipients=${recipients.length}`
|
`jobRoNumber=${jobRoNumber || "N/A"}, bodyShopName=${bodyShopName}, body=${body}, recipients=${recipients.length}`
|
||||||
);
|
);
|
||||||
@@ -238,7 +242,7 @@ const dispatchEmailsToQueue = async ({ emailsToDispatch, logger }) => {
|
|||||||
|
|
||||||
await emailAddQueue.add(
|
await emailAddQueue.add(
|
||||||
"add-email-notification",
|
"add-email-notification",
|
||||||
{ jobId, jobRoNumber, bodyShopName, body, recipients },
|
{ jobId, jobRoNumber, bodyShopName, bodyShopTimezone, body, recipients },
|
||||||
{ jobId: `${jobId}:${Date.now()}` }
|
{ jobId: `${jobId}:${Date.now()}` }
|
||||||
);
|
);
|
||||||
devDebugLogger(`Added email notification to queue for jobId ${jobId} with ${recipients.length} recipients`);
|
devDebugLogger(`Added email notification to queue for jobId ${jobId} with ${recipients.length} recipients`);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ const buildNotification = (data, key, body, variables = {}) => {
|
|||||||
jobId: data.jobId,
|
jobId: data.jobId,
|
||||||
jobRoNumber: data.jobRoNumber,
|
jobRoNumber: data.jobRoNumber,
|
||||||
bodyShopName: data.bodyShopName,
|
bodyShopName: data.bodyShopName,
|
||||||
|
bodyShopTimezone: data.bodyShopTimezone,
|
||||||
body,
|
body,
|
||||||
recipients: []
|
recipients: []
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user