From 70af9981e730ef51c6a1361283b484048793ea25 Mon Sep 17 00:00:00 2001 From: Faruk AYDIN Date: Wed, 21 Sep 2022 02:46:57 +0300 Subject: [PATCH] feat: Implement flow removal with associated records --- .../backend/src/graphql/mutations/delete-flow.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/graphql/mutations/delete-flow.ts b/packages/backend/src/graphql/mutations/delete-flow.ts index 9dcd5409..d7daddc7 100644 --- a/packages/backend/src/graphql/mutations/delete-flow.ts +++ b/packages/backend/src/graphql/mutations/delete-flow.ts @@ -1,4 +1,6 @@ import Context from '../../types/express/context'; +import Execution from '../../models/execution'; +import ExecutionStep from '../../models/execution-step'; type Params = { input: { @@ -11,14 +13,23 @@ const deleteFlow = async ( params: Params, context: Context ) => { - await context.currentUser + const flow = await context.currentUser .$relatedQuery('flows') - .delete() .findOne({ id: params.input.id, }) .throwIfNotFound(); + const executionIds = ( + await flow.$relatedQuery('executions').select('executions.id') + ).map((execution: Execution) => execution.id); + + await ExecutionStep.query().delete().whereIn('execution_id', executionIds); + + await flow.$relatedQuery('executions').delete(); + await flow.$relatedQuery('steps').delete(); + await flow.$query().delete(); + return; };