diff --git a/packages/backend/src/graphql/mutations/update-flow-status.ts b/packages/backend/src/graphql/mutations/update-flow-status.ts index 99a504c2..845af08e 100644 --- a/packages/backend/src/graphql/mutations/update-flow-status.ts +++ b/packages/backend/src/graphql/mutations/update-flow-status.ts @@ -25,14 +25,12 @@ const updateFlowStatus = async ( }) .throwIfNotFound(); - if (flow.active === params.input.active) { + const newActiveValue = params.input.active; + + if (flow.active === newActiveValue) { return flow; } - flow = await flow.$query().withGraphFetched('steps').patchAndFetch({ - active: params.input.active, - }); - const triggerStep = await flow.getTriggerStep(); const trigger = await triggerStep.getTriggerCommand(); const interval = trigger.getInterval?.(triggerStep.parameters); @@ -49,13 +47,13 @@ const updateFlowStatus = async ( testRun: false, }); - if (flow.active && trigger.registerHook) { + if (newActiveValue && trigger.registerHook) { await trigger.registerHook($); - } else if (!flow.active && trigger.unregisterHook) { + } else if (!newActiveValue && trigger.unregisterHook) { await trigger.unregisterHook($); } } else { - if (flow.active) { + if (newActiveValue) { flow = await flow.$query().patchAndFetch({ published_at: new Date().toISOString(), }); @@ -80,6 +78,10 @@ const updateFlowStatus = async ( } } + flow = await flow.$query().withGraphFetched('steps').patchAndFetch({ + active: newActiveValue, + }); + return flow; };