feat: validate action input in updateStep

This commit is contained in:
Ali BARIN
2023-03-12 11:17:41 +00:00
parent dc1002659b
commit 4c4bd267d4
2 changed files with 15 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import { IJSONObject } from '@automatisch/types';
import App from '../../models/app';
import Step from '../../models/step';
import Context from '../../types/express/context';
@@ -42,6 +43,10 @@ const updateStep = async (
}
}
if (step.isAction) {
await App.checkAppAndAction(input.appKey, input.key);
}
step = await Step.query()
.patchAndFetchById(input.id, {
key: input.key,

View File

@@ -36,6 +36,16 @@ class App {
return appInfoConverter(rawAppData);
}
static async checkAppAndAction(appKey: string, actionKey: string): Promise<void> {
const app = await this.findOneByKey(appKey);
const hasAction = app.actions?.find(action => action.key === actionKey);
if (!hasAction) {
throw new Error(`${app.name} does not have an action with the "${actionKey}" key!`);
}
}
}
export default App;