53 lines
1.7 KiB
JavaScript
53 lines
1.7 KiB
JavaScript
const tasksUpdatedCreatedBuilder = require("../scenarioBuilders/tasksUpdatedCreatedBuilder");
|
|
|
|
const notificationScenarios = [
|
|
{ key: "job-assigned-to-me", table: "jobs" },
|
|
{ key: "bill-posted", table: "bills" },
|
|
{ key: "critical-parts-status-changed" },
|
|
{ key: "part-marked-back-ordered" },
|
|
{ key: "new-note-added", table: "notes" },
|
|
{ key: "supplement-imported" },
|
|
{ key: "schedule-dates-changed", table: "jobs" },
|
|
{
|
|
key: "tasks-updated-created",
|
|
table: "tasks",
|
|
fields: ["updated_at"],
|
|
onNew: false,
|
|
builder: tasksUpdatedCreatedBuilder
|
|
},
|
|
{ key: "new-media-added-reassigned" },
|
|
{ key: "new-time-ticket-posted" },
|
|
{ key: "intake-delivery-checklist-completed" },
|
|
{ key: "job-added-to-production", table: "jobs" },
|
|
{ key: "job-status-change", table: "jobs" },
|
|
{ key: "payment-collected-completed" },
|
|
{ key: "alternate-transport-changed" }
|
|
];
|
|
|
|
// Helper function to find a scenario based on multiple criteria
|
|
function hasScenarios({ table, keys, onNew }) {
|
|
return (
|
|
notificationScenarios.find((scenario) => {
|
|
// Check if table matches if provided
|
|
if (table && scenario.table !== table) return false;
|
|
|
|
// Check if key matches if provided
|
|
if (keys && !keys.some((key) => scenario.key === key)) return false;
|
|
|
|
// Check if onNew matches if provided
|
|
if (onNew !== undefined && scenario.onNew !== onNew) return false;
|
|
|
|
return true;
|
|
}) || null
|
|
);
|
|
}
|
|
|
|
// Example usage:
|
|
// console.log(hasScenarios({ table: 'jobs', keys: ['job-assigned-to-me'], onNew: false }));
|
|
// console.log(hasScenarios({ onNew: true, keys: ['tasks-updated-created'] }));
|
|
|
|
module.exports = {
|
|
notificationScenarios,
|
|
hasScenarios
|
|
};
|