refactor: Rename alignStepsPositionsAsOfPosition as updateStepPositionsFrom for flow

This commit is contained in:
Faruk AYDIN
2024-11-01 14:06:26 +01:00
parent d32820ee09
commit 48fcf4dda7
2 changed files with 7 additions and 13 deletions

View File

@@ -166,14 +166,14 @@ class Flow extends Base {
return await this.$relatedQuery('steps').where('position', '>', position); return await this.$relatedQuery('steps').where('position', '>', position);
} }
async alignStepsPositionsAsOfPosition(steps, startPosition) { async updateStepPositionsFrom(startPosition, steps) {
const nextStepQueries = steps.map(async (nextStep, index) => { const stepPositionUpdates = steps.map(async (step, index) => {
return await nextStep.$query().patch({ return await step.$query().patch({
position: startPosition + index, position: startPosition + index,
}); });
}); });
return await Promise.all(nextStepQueries); return await Promise.all(stepPositionUpdates);
} }
async createActionStepAfterStepId(previousStepId) { async createActionStepAfterStepId(previousStepId) {
@@ -185,10 +185,7 @@ class Flow extends Base {
previousStep.position + 1 previousStep.position + 1
); );
await this.alignStepsPositionsAsOfPosition( await this.updateStepPositionsFrom(createdStep.position + 1, nextSteps);
nextSteps,
createdStep.position + 1
);
return createdStep; return createdStep;
} }

View File

@@ -232,17 +232,14 @@ describe('Flow model', () => {
]); ]);
}); });
it('alignStepsPositionsAsOfPosition', async () => { it('updateStepPositionsFrom', async () => {
const flow = await createFlow(); const flow = await createFlow();
await createStep({ type: 'trigger', flowId: flow.id, position: 6 }); await createStep({ type: 'trigger', flowId: flow.id, position: 6 });
await createStep({ type: 'action', flowId: flow.id, position: 8 }); await createStep({ type: 'action', flowId: flow.id, position: 8 });
await createStep({ type: 'action', flowId: flow.id, position: 10 }); await createStep({ type: 'action', flowId: flow.id, position: 10 });
await flow.alignStepsPositionsAsOfPosition( await flow.updateStepPositionsFrom(1, await flow.$relatedQuery('steps'));
await flow.$relatedQuery('steps'),
1
);
expect(await flow.$relatedQuery('steps')).toMatchObject([ expect(await flow.$relatedQuery('steps')).toMatchObject([
{ position: 1, type: 'trigger' }, { position: 1, type: 'trigger' },