(params = {})
| 2 | import { createFlow } from '@/factories/flow.js'; |
| 3 | |
| 4 | export const createStep = async (params = {}) => { |
| 5 | params.flowId = params?.flowId || (await createFlow()).id; |
| 6 | params.type = params?.type || 'action'; |
| 7 | |
| 8 | const lastStep = await Step.query() |
| 9 | .where('flow_id', params.flowId) |
| 10 | .andWhere('deleted_at', null) |
| 11 | .orderBy('position', 'desc') |
| 12 | .limit(1) |
| 13 | .first(); |
| 14 | |
| 15 | params.position = |
| 16 | params?.position || (lastStep?.position ? lastStep.position + 1 : 1); |
| 17 | |
| 18 | params.status = params?.status || 'completed'; |
| 19 | |
| 20 | if (params.appKey !== null) { |
| 21 | params.appKey = |
| 22 | params?.appKey || (params.type === 'action' ? 'deepl' : 'webhook'); |
| 23 | } |
| 24 | |
| 25 | params.parameters = params?.parameters || {}; |
| 26 | |
| 27 | const step = await Step.query().insertAndFetch(params); |
| 28 | |
| 29 | return step; |
| 30 | }; |
no test coverage detected