feat: add paging capability in getFlows query

This commit is contained in:
Ali BARIN
2022-08-05 13:40:03 +02:00
parent ae8f701e5c
commit 5a177b330a
2 changed files with 26 additions and 8 deletions

View File

@@ -1,22 +1,31 @@
import Context from '../../types/express/context';
import paginate from '../../helpers/pagination';
type Params = {
appKey?: string;
limit: number;
offset: number;
};
const getFlows = async (_parent: unknown, params: Params, context: Context) => {
const flowsQuery = context.currentUser
.$relatedQuery('flows')
.withGraphJoined('[steps.[connection]]')
.orderBy('created_at', 'desc');
const userStepsQuery = context.currentUser
.$relatedQuery('steps')
.select('flow_id')
.distinctOn('flow_id');
if (params.appKey) {
flowsQuery.where('steps.app_key', params.appKey);
userStepsQuery.where('app_key', params.appKey);
}
const flows = await flowsQuery;
const flowsQuery = context.currentUser
.$relatedQuery('flows')
.withGraphFetched('[steps.[connection]]')
.whereIn(
'flows.id',
userStepsQuery
);
return flows;
return paginate(flowsQuery, params.limit, params.offset);
};
export default getFlows;