diff --git a/src/domain-services/flows/flow-service.ts b/src/domain-services/flows/flow-service.ts index 8f9983ee..8346128f 100644 --- a/src/domain-services/flows/flow-service.ts +++ b/src/domain-services/flows/flow-service.ts @@ -26,14 +26,42 @@ export class FlowService { constructor() {} async getFlows(args: GetFlowsArgs) { - const { models, conditions, offset, orderBy, limit } = args; + const { models, databaseConnection, conditions, offset, orderBy, limit } = + args; + + let response: FlowEntity[] = []; + if (models) { + // use models find strategy + const findArgs = { + where: conditions, + ...(offset ? { offset } : {}), + ...(limit ? { limit } : {}), + ...(orderBy ? { orderBy } : {}), + }; + response = await models.flow.find(findArgs); + } else if (databaseConnection) { + // use databaseConnection find strategy + let query = databaseConnection + .queryBuilder() + .select('*') + .from('flow') + .where(prepareCondition(conditions)); - return await models!.flow.find({ - orderBy, - limit, - where: conditions, - offset, - }); + if (orderBy) { + query = query.orderBy(orderBy.column, orderBy.order); + } + + if (limit) { + query = query.limit(limit); + } + if (offset) { + query = query.offset(offset); + } + + response = await query; + } + + return response; } async getFlowsAsUniqueFlowEntity( diff --git a/src/domain-services/flows/strategy/impl/search-flow-by-filters-strategy-impl.ts b/src/domain-services/flows/strategy/impl/search-flow-by-filters-strategy-impl.ts index 6908326e..89e31fb8 100644 --- a/src/domain-services/flows/strategy/impl/search-flow-by-filters-strategy-impl.ts +++ b/src/domain-services/flows/strategy/impl/search-flow-by-filters-strategy-impl.ts @@ -267,9 +267,10 @@ export class SearchFlowByFiltersStrategy implements FlowSearchStrategy { // And collect the flows const chunkSearchConditions = this.buildConditions(chunk, flowFilters); const flowsChunk = await this.flowService.getFlows({ - models, + databaseConnection, conditions: chunkSearchConditions, orderBy: orderByForFlow, + limit: chunkSize, }); flows.push(...flowsChunk); } @@ -277,9 +278,10 @@ export class SearchFlowByFiltersStrategy implements FlowSearchStrategy { // Once the list of elements is reduced, we need to build the conditions const searchConditions = this.buildConditions(reducedFlows); flows = await this.flowService.getFlows({ - models, + databaseConnection, conditions: searchConditions, orderBy: orderByForFlow, + limit, }); } return { flows, count };