feat: validate trigger input in updateStep

This commit is contained in:
Ali BARIN
2023-03-12 11:18:04 +00:00
parent 4c4bd267d4
commit db55912f78
2 changed files with 14 additions and 0 deletions

View File

@@ -43,6 +43,10 @@ const updateStep = async (
}
}
if (step.isTrigger) {
await App.checkAppAndTrigger(input.appKey, input.key);
}
if (step.isAction) {
await App.checkAppAndAction(input.appKey, input.key);
}

View File

@@ -46,6 +46,16 @@ class App {
throw new Error(`${app.name} does not have an action with the "${actionKey}" key!`);
}
}
static async checkAppAndTrigger(appKey: string, triggerKey: string): Promise<void> {
const app = await this.findOneByKey(appKey);
const hasTrigger = app.triggers?.find(trigger => trigger.key === triggerKey);
if (!hasTrigger) {
throw new Error(`${app.name} does not have a trigger with the "${triggerKey}" key!`);
}
}
}
export default App;