feat: Implement flow removal with associated records
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
|
import Execution from '../../models/execution';
|
||||||
|
import ExecutionStep from '../../models/execution-step';
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
input: {
|
input: {
|
||||||
@@ -11,14 +13,23 @@ const deleteFlow = async (
|
|||||||
params: Params,
|
params: Params,
|
||||||
context: Context
|
context: Context
|
||||||
) => {
|
) => {
|
||||||
await context.currentUser
|
const flow = await context.currentUser
|
||||||
.$relatedQuery('flows')
|
.$relatedQuery('flows')
|
||||||
.delete()
|
|
||||||
.findOne({
|
.findOne({
|
||||||
id: params.input.id,
|
id: params.input.id,
|
||||||
})
|
})
|
||||||
.throwIfNotFound();
|
.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;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user