From a08dee23cde714641f5959cd8b7b63a56614df87 Mon Sep 17 00:00:00 2001 From: manelcecs Date: Thu, 11 Apr 2024 11:22:26 +0200 Subject: [PATCH] Temp: fix how find flows works Will be updated with correct code --- src/domain-services/flows/flow-service.ts | 42 +++++++++++++++---- .../search-flow-by-filters-strategy-impl.ts | 6 ++- 2 files changed, 39 insertions(+), 9 deletions(-) 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 };