refactor: Do not pass response object to throw validation error
This commit is contained in:
@@ -2,11 +2,7 @@ import { renderObject } from '../../../../helpers/renderer.js';
|
|||||||
import importFlow from '../../../../helpers/import-flow.js';
|
import importFlow from '../../../../helpers/import-flow.js';
|
||||||
|
|
||||||
export default async function importFlowController(request, response) {
|
export default async function importFlowController(request, response) {
|
||||||
const flow = await importFlow(
|
const flow = await importFlow(request.currentUser, flowParams(request));
|
||||||
request.currentUser,
|
|
||||||
flowParams(request),
|
|
||||||
response
|
|
||||||
);
|
|
||||||
|
|
||||||
return renderObject(response, flow, { status: 201 });
|
return renderObject(response, flow, { status: 201 });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,12 @@
|
|||||||
import Crypto from 'crypto';
|
import Crypto from 'crypto';
|
||||||
import Step from '../models/step.js';
|
import Step from '../models/step.js';
|
||||||
import { renderObjectionError } from './renderer.js';
|
import { ValidationError } from 'objection';
|
||||||
|
|
||||||
const importFlow = async (user, flowData, response) => {
|
const importFlow = async (user, flowData) => {
|
||||||
const steps = flowData.steps || [];
|
const steps = flowData.steps || [];
|
||||||
|
|
||||||
// Validation: the first step must be a trigger
|
|
||||||
if (!steps.length || steps[0].type !== 'trigger') {
|
if (!steps.length || steps[0].type !== 'trigger') {
|
||||||
return renderObjectionError(response, {
|
throw new ValidationError({
|
||||||
statusCode: 422,
|
|
||||||
type: 'ValidationError',
|
type: 'ValidationError',
|
||||||
data: {
|
data: {
|
||||||
steps: [{ message: 'The first step must be a trigger!' }],
|
steps: [{ message: 'The first step must be a trigger!' }],
|
||||||
|
|||||||
Reference in New Issue
Block a user