chore: Add step validation to import step API endpoint

This commit is contained in:
Faruk AYDIN
2025-01-20 14:53:48 +01:00
parent 28a74f0cb2
commit 109f628921
3 changed files with 49 additions and 5 deletions

View File

@@ -1,10 +1,23 @@
import Crypto from 'crypto';
import Step from '../models/step.js';
import { renderObjectionError } from './renderer.js';
const importFlow = async (user, flowData) => {
const newFlowId = Crypto.randomUUID();
const importFlow = async (user, flowData, response) => {
const steps = flowData.steps || [];
// Validation: the first step must be a trigger
if (!steps.length || steps[0].type !== 'trigger') {
return renderObjectionError(response, {
statusCode: 422,
type: 'ValidationError',
data: {
steps: [{ message: 'The first step must be a trigger!' }],
},
});
}
const newFlowId = Crypto.randomUUID();
const newFlow = await user.$relatedQuery('flows').insertAndFetch({
id: newFlowId,
name: flowData.name,