feat: Implement delete step rest API endpoint

This commit is contained in:
Faruk AYDIN
2024-08-23 16:53:14 +03:00
parent 5af1d94fc0
commit 0cf9bc1a32
6 changed files with 178 additions and 2 deletions

View File

@@ -207,7 +207,9 @@ class Step extends Base {
const additionalFields = setupField.additionalFields;
if (additionalFields) {
const keyArgument = additionalFields.arguments.find(argument => argument.name === 'key');
const keyArgument = additionalFields.arguments.find(
(argument) => argument.name === 'key'
);
const dynamicFieldsKey = keyArgument.value;
const dynamicFields = await this.createDynamicFields(
@@ -289,6 +291,25 @@ class Step extends Base {
return this;
}
async delete() {
await this.$relatedQuery('executionSteps').delete();
await this.$query().delete();
const flow = await this.$relatedQuery('flow');
const nextSteps = await flow
.$relatedQuery('steps')
.where('position', '>', this.position);
const nextStepQueries = nextSteps.map(async (nextStep) => {
await nextStep.$query().patch({
position: nextStep.position - 1,
});
});
await Promise.all(nextStepQueries);
}
}
export default Step;