IO-3166-Global-Notifications-Part-2: checkpoint
This commit is contained in:
@@ -452,7 +452,6 @@ const paymentCollectedCompletedBuilder = (data) => {
|
||||
* Builds notification data for changes to scheduled dates.
|
||||
*/
|
||||
const scheduledDatesChangedBuilder = (data) => {
|
||||
const momentFormat = "MM/DD/YYYY hh:mm a";
|
||||
const changedFields = data.changedFields;
|
||||
|
||||
// Define field configurations
|
||||
@@ -462,16 +461,38 @@ const scheduledDatesChangedBuilder = (data) => {
|
||||
scheduled_delivery: "Scheduled Delivery"
|
||||
};
|
||||
|
||||
// Helper function to format date and time with "at"
|
||||
const formatDateTime = (date) => {
|
||||
if (!date) return "unset";
|
||||
const formatted = moment(date).tz(data.bodyShopTimezone);
|
||||
const datePart = formatted.format("MM/DD/YYYY");
|
||||
const timePart = formatted.format("hh:mm a");
|
||||
return `${datePart} at ${timePart}`;
|
||||
};
|
||||
|
||||
// Build field messages dynamically
|
||||
const fieldMessages = Object.entries(fieldConfigs)
|
||||
.filter(([field]) => changedFields[field]) // Only include changed fields
|
||||
.map(([field, label]) => {
|
||||
const { old, new: newValue } = changedFields[field];
|
||||
const formatDate = (date) => (date ? moment(date).tz(data.bodyShopTimezone).format(momentFormat) : "unset");
|
||||
return `${label} changed from ${formatDate(old)} to ${formatDate(newValue)}`;
|
||||
});
|
||||
|
||||
const body = fieldMessages.length > 0 ? fieldMessages.join(", ") + "." : "Scheduled dates have been updated.";
|
||||
// Case 1: Scheduled date cancelled (from value to null)
|
||||
if (old && !newValue) {
|
||||
return `${label} was cancelled (previously ${formatDateTime(old)}).`;
|
||||
}
|
||||
// Case 2: Scheduled date set (from null to value)
|
||||
else if (!old && newValue) {
|
||||
return `${label} was set to ${formatDateTime(newValue)}.`;
|
||||
}
|
||||
// Case 3: Scheduled date changed (from value to value)
|
||||
else if (old && newValue) {
|
||||
return `${label} changed from ${formatDateTime(old)} to ${formatDateTime(newValue)}.`;
|
||||
}
|
||||
return ""; // Fallback, though this shouldn't happen with the filter
|
||||
})
|
||||
.filter(Boolean); // Remove any empty strings
|
||||
|
||||
const body = fieldMessages.length > 0 ? fieldMessages.join(" ") : "Scheduled dates have been updated.";
|
||||
|
||||
const result = {
|
||||
app: {
|
||||
|
||||
@@ -37,10 +37,11 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
// Step 1: Validate we know what user committed the action that fired the parser
|
||||
// console.log("Step 1");
|
||||
|
||||
const hasuraUserRole = event?.session_variables?.["x-hasura-role"];
|
||||
const hasuraUserId = event?.session_variables?.["x-hasura-user-id"];
|
||||
|
||||
// Bail if we don't know who started the scenario
|
||||
if (!hasuraUserId) {
|
||||
if (hasuraUserRole === "user" && !hasuraUserId) {
|
||||
logger.log("No Hasura user ID found, skipping notification parsing", "info", "notifications");
|
||||
return;
|
||||
}
|
||||
@@ -84,7 +85,7 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
authId: watcher?.user?.authid
|
||||
}));
|
||||
|
||||
if (FILTER_SELF_FROM_WATCHERS) {
|
||||
if (FILTER_SELF_FROM_WATCHERS && hasuraUserRole === "user") {
|
||||
jobWatchers = jobWatchers.filter((watcher) => watcher.authId !== hasuraUserId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user