chore: Do not override query method for findOne query errors
This commit is contained in:

committed by
Ömer Faruk Aydın

parent
3e4768c106
commit
79b12ac9e6
@@ -10,7 +10,7 @@ const createAuthDataResolver = async (params: Params, req: RequestWithCurrentUse
|
|||||||
const connection = await Connection.query().findOne({
|
const connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||||
|
|
||||||
|
@@ -16,7 +16,7 @@ const createStepResolver = async (params: Params, req: RequestWithCurrentUser) =
|
|||||||
const flow = await Flow.query().findOne({
|
const flow = await Flow.query().findOne({
|
||||||
id: params.flowId,
|
id: params.flowId,
|
||||||
user_id: req.currentUser.id
|
user_id: req.currentUser.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
const step = await Step.query().insertAndFetch({
|
const step = await Step.query().insertAndFetch({
|
||||||
flowId: flow.id,
|
flowId: flow.id,
|
||||||
|
@@ -10,7 +10,7 @@ const deleteConnectionResolver = async (params: Params, req: RequestWithCurrentU
|
|||||||
await Connection.query().delete().findOne({
|
await Connection.query().delete().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -12,11 +12,11 @@ type Params = {
|
|||||||
const executeStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
const executeStepResolver = async (params: Params, req: RequestWithCurrentUser) => {
|
||||||
let step = await Step.query().findOne({
|
let step = await Step.query().findOne({
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
let connection = await Connection.query().findOne({
|
let connection = await Connection.query().findOne({
|
||||||
id: step.connectionId
|
id: step.connectionId
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${step.appKey}`)).default;
|
const appClass = (await import(`../../apps/${step.appKey}`)).default;
|
||||||
const appInstance = new appClass(connection.data);
|
const appInstance = new appClass(connection.data);
|
||||||
|
@@ -11,7 +11,7 @@ const resetConnectionResolver = async (params: Params, req: RequestWithCurrentUs
|
|||||||
let connection = await Connection.query().findOne({
|
let connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
connection = await connection.$query().patchAndFetch({
|
connection = await connection.$query().patchAndFetch({
|
||||||
data: { screenName: connection.data.screenName }
|
data: { screenName: connection.data.screenName }
|
||||||
|
@@ -12,7 +12,7 @@ const updateConnectionResolver = async (params: Params, req: RequestWithCurrentU
|
|||||||
let connection = await Connection.query().findOne({
|
let connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
connection = await connection.$query().patchAndFetch({
|
connection = await connection.$query().patchAndFetch({
|
||||||
data: {
|
data: {
|
||||||
|
@@ -10,7 +10,7 @@ const verifyConnectionResolver = async (params: Params, req: RequestWithCurrentU
|
|||||||
let connection = await Connection.query().findOne({
|
let connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||||
|
|
||||||
|
@@ -11,7 +11,7 @@ const testConnectionResolver = async (params: Params, req: RequestWithCurrentUse
|
|||||||
let connection = await Connection.query().findOne({
|
let connection = await Connection.query().findOne({
|
||||||
user_id: req.currentUser.id,
|
user_id: req.currentUser.id,
|
||||||
id: params.id
|
id: params.id
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
const appClass = (await import(`../../apps/${connection.key}`)).default;
|
||||||
|
|
||||||
|
@@ -6,7 +6,7 @@ const authentication = async (req: RequestWithCurrentUser, _res: Response, next:
|
|||||||
// We set authentication to use the sample user we created temporarily.
|
// We set authentication to use the sample user we created temporarily.
|
||||||
req.currentUser = await User.query().findOne({
|
req.currentUser = await User.query().findOne({
|
||||||
email: 'user@automatisch.com'
|
email: 'user@automatisch.com'
|
||||||
})
|
}).throwIfNotFound();
|
||||||
|
|
||||||
next()
|
next()
|
||||||
}
|
}
|
||||||
|
@@ -9,13 +9,6 @@ class Base extends Model {
|
|||||||
return snakeCaseMappers();
|
return snakeCaseMappers();
|
||||||
}
|
}
|
||||||
|
|
||||||
static query<M extends Model>(
|
|
||||||
this: Constructor<M>,
|
|
||||||
trxOrKnex?: TransactionOrKnex
|
|
||||||
): QueryBuilderType<M> {
|
|
||||||
return super.query(trxOrKnex).throwIfNotFound() as QueryBuilderType<M>;
|
|
||||||
};
|
|
||||||
|
|
||||||
async $beforeInsert(queryContext: QueryContext) {
|
async $beforeInsert(queryContext: QueryContext) {
|
||||||
await super.$beforeInsert(queryContext);
|
await super.$beforeInsert(queryContext);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user