Merge pull request #399 from automatisch/refactor/flows-query
refactor: Use currentUser with context for flows query
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import Context from '../../types/express/context';
|
import Context from '../../types/express/context';
|
||||||
import paginate from '../../helpers/pagination';
|
import paginate from '../../helpers/pagination';
|
||||||
import Flow from '../../models/flow';
|
|
||||||
|
|
||||||
type Params = {
|
type Params = {
|
||||||
appKey?: string;
|
appKey?: string;
|
||||||
@@ -9,11 +8,11 @@ type Params = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const getFlows = async (_parent: unknown, params: Params, context: Context) => {
|
const getFlows = async (_parent: unknown, params: Params, context: Context) => {
|
||||||
const flowsQuery = Flow.query()
|
const flowsQuery = context.currentUser
|
||||||
|
.$relatedQuery('flows')
|
||||||
.joinRelated('steps')
|
.joinRelated('steps')
|
||||||
.withGraphFetched('steps.[connection]')
|
.withGraphFetched('steps.[connection]')
|
||||||
.where('flows.user_id', context.currentUser.id)
|
.where((builder) => {
|
||||||
.andWhere((builder) => {
|
|
||||||
if (params.appKey) {
|
if (params.appKey) {
|
||||||
builder.where('steps.app_key', params.appKey);
|
builder.where('steps.app_key', params.appKey);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user