feat: validate action input in updateStep
This commit is contained in:
@@ -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,
|
||||
|
@@ -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;
|
||||
|
Reference in New Issue
Block a user