diff --git a/packages/backend/src/graphql/mutations/create-auth-data.ts b/packages/backend/src/graphql/mutations/create-auth-data.ts index 7648c4e3..eb1e719f 100644 --- a/packages/backend/src/graphql/mutations/create-auth-data.ts +++ b/packages/backend/src/graphql/mutations/create-auth-data.ts @@ -10,7 +10,7 @@ const createAuthDataResolver = async (params: Params, req: RequestWithCurrentUse const connection = await Connection.query().findOne({ user_id: req.currentUser.id, id: params.id - }) + }).throwIfNotFound(); const appClass = (await import(`../../apps/${connection.key}`)).default; diff --git a/packages/backend/src/graphql/mutations/create-step.ts b/packages/backend/src/graphql/mutations/create-step.ts index d822ac8c..b4c9ed92 100644 --- a/packages/backend/src/graphql/mutations/create-step.ts +++ b/packages/backend/src/graphql/mutations/create-step.ts @@ -16,7 +16,7 @@ const createStepResolver = async (params: Params, req: RequestWithCurrentUser) = const flow = await Flow.query().findOne({ id: params.flowId, user_id: req.currentUser.id - }) + }).throwIfNotFound(); const step = await Step.query().insertAndFetch({ flowId: flow.id, diff --git a/packages/backend/src/graphql/mutations/delete-connection.ts b/packages/backend/src/graphql/mutations/delete-connection.ts index 43168080..cb2170ba 100644 --- a/packages/backend/src/graphql/mutations/delete-connection.ts +++ b/packages/backend/src/graphql/mutations/delete-connection.ts @@ -10,7 +10,7 @@ const deleteConnectionResolver = async (params: Params, req: RequestWithCurrentU await Connection.query().delete().findOne({ user_id: req.currentUser.id, id: params.id - }) + }).throwIfNotFound(); return; } diff --git a/packages/backend/src/graphql/mutations/execute-step.ts b/packages/backend/src/graphql/mutations/execute-step.ts index ad993c4d..570c4e1e 100644 --- a/packages/backend/src/graphql/mutations/execute-step.ts +++ b/packages/backend/src/graphql/mutations/execute-step.ts @@ -12,11 +12,11 @@ type Params = { const executeStepResolver = async (params: Params, req: RequestWithCurrentUser) => { let step = await Step.query().findOne({ id: params.id - }) + }).throwIfNotFound(); let connection = await Connection.query().findOne({ id: step.connectionId - }) + }).throwIfNotFound(); const appClass = (await import(`../../apps/${step.appKey}`)).default; const appInstance = new appClass(connection.data); diff --git a/packages/backend/src/graphql/mutations/reset-connection.ts b/packages/backend/src/graphql/mutations/reset-connection.ts index 06579b66..af67dd9a 100644 --- a/packages/backend/src/graphql/mutations/reset-connection.ts +++ b/packages/backend/src/graphql/mutations/reset-connection.ts @@ -11,7 +11,7 @@ const resetConnectionResolver = async (params: Params, req: RequestWithCurrentUs let connection = await Connection.query().findOne({ user_id: req.currentUser.id, id: params.id - }) + }).throwIfNotFound(); connection = await connection.$query().patchAndFetch({ data: { screenName: connection.data.screenName } diff --git a/packages/backend/src/graphql/mutations/update-connection.ts b/packages/backend/src/graphql/mutations/update-connection.ts index 6b7a1063..aada26bc 100644 --- a/packages/backend/src/graphql/mutations/update-connection.ts +++ b/packages/backend/src/graphql/mutations/update-connection.ts @@ -12,7 +12,7 @@ const updateConnectionResolver = async (params: Params, req: RequestWithCurrentU let connection = await Connection.query().findOne({ user_id: req.currentUser.id, id: params.id - }) + }).throwIfNotFound(); connection = await connection.$query().patchAndFetch({ data: { diff --git a/packages/backend/src/graphql/mutations/verify-connection.ts b/packages/backend/src/graphql/mutations/verify-connection.ts index 0692e46d..21f2a0c4 100644 --- a/packages/backend/src/graphql/mutations/verify-connection.ts +++ b/packages/backend/src/graphql/mutations/verify-connection.ts @@ -10,7 +10,7 @@ const verifyConnectionResolver = async (params: Params, req: RequestWithCurrentU let connection = await Connection.query().findOne({ user_id: req.currentUser.id, id: params.id - }) + }).throwIfNotFound(); const appClass = (await import(`../../apps/${connection.key}`)).default; diff --git a/packages/backend/src/graphql/queries/test-connection.ts b/packages/backend/src/graphql/queries/test-connection.ts index 93befc5b..f264750e 100644 --- a/packages/backend/src/graphql/queries/test-connection.ts +++ b/packages/backend/src/graphql/queries/test-connection.ts @@ -11,7 +11,7 @@ const testConnectionResolver = async (params: Params, req: RequestWithCurrentUse let connection = await Connection.query().findOne({ user_id: req.currentUser.id, id: params.id - }) + }).throwIfNotFound(); const appClass = (await import(`../../apps/${connection.key}`)).default; diff --git a/packages/backend/src/helpers/authentication.ts b/packages/backend/src/helpers/authentication.ts index c5fc9f06..b858370d 100644 --- a/packages/backend/src/helpers/authentication.ts +++ b/packages/backend/src/helpers/authentication.ts @@ -6,7 +6,7 @@ const authentication = async (req: RequestWithCurrentUser, _res: Response, next: // We set authentication to use the sample user we created temporarily. req.currentUser = await User.query().findOne({ email: 'user@automatisch.com' - }) + }).throwIfNotFound(); next() } diff --git a/packages/backend/src/models/base.ts b/packages/backend/src/models/base.ts index 38b703fe..59909592 100644 --- a/packages/backend/src/models/base.ts +++ b/packages/backend/src/models/base.ts @@ -9,13 +9,6 @@ class Base extends Model { return snakeCaseMappers(); } - static query( - this: Constructor, - trxOrKnex?: TransactionOrKnex - ): QueryBuilderType { - return super.query(trxOrKnex).throwIfNotFound() as QueryBuilderType; - }; - async $beforeInsert(queryContext: QueryContext) { await super.$beforeInsert(queryContext);