From db55912f78ea7b80fbe3a40157c45c9c71809061 Mon Sep 17 00:00:00 2001 From: Ali BARIN Date: Sun, 12 Mar 2023 11:18:04 +0000 Subject: [PATCH] feat: validate trigger input in updateStep --- packages/backend/src/graphql/mutations/update-step.ts | 4 ++++ packages/backend/src/models/app.ts | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/packages/backend/src/graphql/mutations/update-step.ts b/packages/backend/src/graphql/mutations/update-step.ts index d65ffecc..11398287 100644 --- a/packages/backend/src/graphql/mutations/update-step.ts +++ b/packages/backend/src/graphql/mutations/update-step.ts @@ -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); } diff --git a/packages/backend/src/models/app.ts b/packages/backend/src/models/app.ts index f5cb4b36..d50d3426 100644 --- a/packages/backend/src/models/app.ts +++ b/packages/backend/src/models/app.ts @@ -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 { + 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;