chore: remove redundant delete step mutation

This commit is contained in:
Ali BARIN
2024-09-18 15:50:01 +00:00
committed by Faruk AYDIN
parent f94a5385d7
commit 1297f5d43c
4 changed files with 0 additions and 61 deletions

View File

@@ -1,40 +0,0 @@
import Step from '../../models/step.js';
const deleteStep = async (_parent, params, context) => {
const conditions = context.currentUser.can('update', 'Flow');
const isCreator = conditions.isCreator;
const allSteps = Step.query();
const userSteps = context.currentUser.$relatedQuery('steps');
const baseQuery = isCreator ? userSteps : allSteps;
const step = await baseQuery
.withGraphFetched('flow')
.findOne({
'steps.id': params.input.id,
})
.throwIfNotFound();
await step.$relatedQuery('executionSteps').delete();
await step.$query().delete();
const nextSteps = await step.flow
.$relatedQuery('steps')
.where('position', '>', step.position);
const nextStepQueries = nextSteps.map(async (nextStep) => {
await nextStep.$query().patch({
position: nextStep.position - 1,
});
});
await Promise.all(nextStepQueries);
step.flow = await step.flow
.$query()
.withGraphJoined('steps')
.orderBy('steps.position', 'asc');
return step;
};
export default deleteStep;