Linden Crandall 5075f5c5d8
Some checks are pending
Automatisch Backend Tests / test (push) Waiting to run
Automatisch CI / linter (push) Waiting to run
Automatisch CI / start-backend-server (push) Waiting to run
Automatisch CI / start-backend-worker (push) Waiting to run
Automatisch CI / build-web (push) Waiting to run
Automatisch UI Tests / test (push) Waiting to run
commit upstream files
2025-02-06 04:14:18 +09:00

31 lines
808 B
JavaScript

import Step from '../../src/models/step';
import { createFlow } from './flow';
export const createStep = async (params = {}) => {
params.flowId = params?.flowId || (await createFlow()).id;
params.type = params?.type || 'action';
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 ? lastStep.position + 1 : 1);
params.status = params?.status || 'completed';
if (params.appKey !== null) {
params.appKey =
params?.appKey || (params.type === 'action' ? 'deepl' : 'webhook');
}
params.parameters = params?.parameters || {};
const step = await Step.query().insertAndFetch(params);
return step;
};