refactor: Use currentUser with context for flows query

This commit is contained in:
Faruk AYDIN
2022-08-06 23:31:09 +03:00
parent 1f9dd6a3bc
commit 280c7832ae

View File

@@ -1,6 +1,5 @@
import Context from '../../types/express/context';
import paginate from '../../helpers/pagination';
import Flow from '../../models/flow';
type Params = {
appKey?: string;
@@ -9,11 +8,11 @@ type Params = {
};
const getFlows = async (_parent: unknown, params: Params, context: Context) => {
const flowsQuery = Flow.query()
const flowsQuery = context.currentUser
.$relatedQuery('flows')
.joinRelated('steps')
.withGraphFetched('steps.[connection]')
.where('flows.user_id', context.currentUser.id)
.andWhere((builder) => {
.where((builder) => {
if (params.appKey) {
builder.where('steps.app_key', params.appKey);
}