feat: validate app input in createFlow

This commit is contained in:
Ali BARIN
2023-03-12 11:20:59 +00:00
parent db55912f78
commit ba27fc12e8

View File

@@ -1,3 +1,4 @@
import App from '../../models/app';
import Step from '../../models/step';
import Context from '../../types/express/context';
@@ -16,15 +17,20 @@ const createFlow = async (
const connectionId = params?.input?.connectionId;
const appKey = params?.input?.triggerAppKey;
await App.findOneByKey(appKey);
const flow = await context.currentUser.$relatedQuery('flows').insert({
name: 'Name your flow',
});
if (connectionId) {
await context.currentUser
const hasConnection = await context.currentUser
.$relatedQuery('connections')
.findById(connectionId)
.throwIfNotFound();
.findById(connectionId);
if (!hasConnection) {
throw new Error('The connection does not exist!');
}
}
await Step.query().insert({