35 lines
1.0 KiB
JavaScript
35 lines
1.0 KiB
JavaScript
const changeParser = require("../utils/changeParser");
|
|
const { hasScenarios } = require("../utils/scenarioMapperr");
|
|
const handleTasksChange = async (req, res) => {
|
|
try {
|
|
// Step 1: Parse the changes
|
|
const changes = await changeParser({
|
|
newData: req?.body?.event?.data?.new,
|
|
oldData: req?.body?.event?.data?.old,
|
|
trigger: req?.body?.trigger,
|
|
table: req?.body?.table
|
|
});
|
|
|
|
console.dir(changes, { depth: null });
|
|
|
|
const scenarios = hasScenarios({
|
|
table: changes.table.name,
|
|
keys: changes.changedFieldNames,
|
|
onNew: changes.isNew
|
|
});
|
|
|
|
console.dir(scenarios, { depth: null });
|
|
// Step 2: See if any scenarios match the changes
|
|
// Step 3: Handle the scenario
|
|
} catch (error) {
|
|
console.error("Error handling tasks change:", error);
|
|
return res.status(500).json({ message: "Error handling tasks change." });
|
|
}
|
|
|
|
// Get Bodyshop from hasura user id,
|
|
|
|
return res.status(200).json({ message: "Tasks change handled." });
|
|
};
|
|
//
|
|
module.exports = handleTasksChange;
|