feature/IO-3096-GlobalNotifications - Checkpoint
This commit is contained in:
@@ -19,6 +19,7 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
}
|
||||
|
||||
// Step 1: Parse event data to extract necessary details.
|
||||
// console.log(`1`);
|
||||
const eventData = await eventParser({
|
||||
newData: event.data.new,
|
||||
oldData: event.data.old,
|
||||
@@ -28,6 +29,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
});
|
||||
|
||||
// Step 2: Query job watchers for the given job ID.
|
||||
// console.log(`2`);
|
||||
|
||||
const watcherData = await gqlClient.request(queries.GET_JOB_WATCHERS, {
|
||||
jobid: eventData.jobId
|
||||
});
|
||||
@@ -44,6 +47,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
}
|
||||
|
||||
// Step 3: Retrieve body shop information from the job.
|
||||
// console.log(`3`);
|
||||
|
||||
const bodyShopId = watcherData?.job?.bodyshop?.id;
|
||||
const bodyShopName = watcherData?.job?.bodyshop?.shopname;
|
||||
|
||||
@@ -52,6 +57,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
}
|
||||
|
||||
// Step 4: Determine matching scenarios based on event data.
|
||||
// console.log(`4`);
|
||||
|
||||
const matchingScenarios = getMatchingScenarios({
|
||||
...eventData,
|
||||
jobWatchers,
|
||||
@@ -72,6 +79,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
};
|
||||
|
||||
// Step 5: Query notification settings for job watchers.
|
||||
// console.log(`5`);
|
||||
|
||||
const associationsData = await gqlClient.request(queries.GET_NOTIFICATION_ASSOCIATIONS, {
|
||||
emails: jobWatchers.map((x) => x.email),
|
||||
shopid: bodyShopId
|
||||
@@ -82,6 +91,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
}
|
||||
|
||||
// Step 6: Filter scenario watchers based on enabled notification methods.
|
||||
// console.log(`6`);
|
||||
|
||||
finalScenarioData.matchingScenarios = finalScenarioData.matchingScenarios.map((scenario) => ({
|
||||
...scenario,
|
||||
scenarioWatchers: associationsData.associations
|
||||
@@ -111,6 +122,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
}
|
||||
|
||||
// Step 7: Trigger scenario builders for matching scenarios with eligible watchers.
|
||||
// console.log(`7`);
|
||||
|
||||
for (const scenario of finalScenarioData.matchingScenarios) {
|
||||
if (isEmpty(scenario.scenarioWatchers) || !isFunction(scenario.builder)) {
|
||||
continue;
|
||||
@@ -132,6 +145,8 @@ const scenarioParser = async (req, jobIdField) => {
|
||||
}
|
||||
|
||||
// Step 8: Filter scenario fields to only include changed fields.
|
||||
// console.log(`8`);
|
||||
|
||||
const filteredScenarioFields =
|
||||
scenario.fields?.filter((field) => eventData.changedFieldNames.includes(field)) || [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user