Skip to content

Commit

Permalink
Temp: fix how find flows works
Browse files Browse the repository at this point in the history
Will be updated with correct code
  • Loading branch information
manelcecs committed Apr 11, 2024
1 parent 4c2097c commit a08dee2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 9 deletions.
42 changes: 35 additions & 7 deletions src/domain-services/flows/flow-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,19 +267,21 @@ 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);
}
} else {
// 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 };
Expand Down

0 comments on commit a08dee2

Please sign in to comment.