fix: Order associated steps by position for the flow

This commit is contained in:
Faruk AYDIN
2022-08-07 12:45:59 +03:00
committed by Ali BARIN
parent 03cfa8b904
commit 2e980664ac

View File

@@ -1,5 +1,5 @@
import { ValidationError } from 'objection'; import { ValidationError } from 'objection';
import type { ModelOptions, QueryContext } from 'objection'; import type { ModelOptions, QueryContext, QueryBuilder } from 'objection';
import Base from './base'; import Base from './base';
import Step from './step'; import Step from './step';
import Execution from './execution'; import Execution from './execution';
@@ -33,6 +33,9 @@ class Flow extends Base {
from: 'flows.id', from: 'flows.id',
to: 'steps.flow_id', to: 'steps.flow_id',
}, },
filter(builder: QueryBuilder<Step>) {
builder.orderBy('position', 'asc');
},
}, },
executions: { executions: {
relation: Base.HasManyRelation, relation: Base.HasManyRelation,
@@ -44,7 +47,10 @@ class Flow extends Base {
}, },
}); });
async $beforeUpdate(opt: ModelOptions, queryContext: QueryContext): Promise<void> { async $beforeUpdate(
opt: ModelOptions,
queryContext: QueryContext
): Promise<void> {
await super.$beforeUpdate(opt, queryContext); await super.$beforeUpdate(opt, queryContext);
if (!this.active) return; if (!this.active) return;