Merge pull request #1752 from automatisch/fix-step-factory

fix: Adjust step factory to use objection instead of knex
This commit is contained in:
Ömer Faruk Aydın
2024-03-20 02:15:13 +01:00
committed by GitHub
2 changed files with 11 additions and 9 deletions

View File

@@ -136,7 +136,7 @@ describe('graphQL getFlow query', () => {
id: actionStep.id,
key: 'translateText',
parameters: {},
position: 1,
position: 2,
status: actionStep.status,
type: 'action',
webhookUrl: 'http://localhost:3000/null',
@@ -223,7 +223,7 @@ describe('graphQL getFlow query', () => {
id: actionStep.id,
key: 'translateText',
parameters: {},
position: 1,
position: 2,
status: actionStep.status,
type: 'action',
webhookUrl: 'http://localhost:3000/null',

View File

@@ -5,19 +5,21 @@ export const createStep = async (params = {}) => {
params.flowId = params?.flowId || (await createFlow()).id;
params.type = params?.type || 'action';
const lastStep = await global.knex
.table('steps')
.where('flowId', params.flowId)
.andWhere('deletedAt', '!=', null)
.orderBy('createdAt', 'desc')
const lastStep = await Step.query()
.where('flow_id', params.flowId)
.andWhere('deleted_at', null)
.orderBy('position', 'desc')
.limit(1)
.first();
params.position = params?.position || (lastStep?.position || 0) + 1;
params.position =
params?.position || (lastStep?.position ? lastStep.position + 1 : 1);
params.status = params?.status || 'completed';
params.appKey =
params?.appKey || (params.type === 'action' ? 'deepl' : 'webhook');
const step = await Step.query().insert(params).returning('*');
const step = await Step.query().insertAndFetch(params);
return step;
};