1+ import { type FlowId } from '@unocha/hpc-api-core/src/db/models/flow' ;
12import { Service } from 'typedi' ;
23import { FlowObjectFilterGrouped } from '../../../flow-object/model' ;
34import { FlowService } from '../../flow-service' ;
@@ -13,6 +14,7 @@ import { GetFlowIdsFromNestedFlowFiltersStrategyImpl } from './get-flowIds-flow-
1314import { GetFlowIdsFromObjectConditionsStrategyImpl } from './get-flowIds-flow-object-conditions-strategy-impl' ;
1415import {
1516 defaultSearchFlowFilter ,
17+ intersectExclusiveSets ,
1618 intersectSets ,
1719 mapFlowFiltersToFlowObjectFiltersGrouped ,
1820 mapFlowOrderBy ,
@@ -161,10 +163,19 @@ export class SearchFlowByFiltersStrategy implements FlowSearchStrategy {
161163 didFlowsFromObjectFiltersPromiseCreated = true ;
162164 }
163165 const flowsFromObjectFilters = await flowsFromObjectFiltersPromise ;
164- const flowSearchIds = intersectSets (
165- intersectCandidates ,
166- new Set ( flowsFromObjectFilters . flows . map ( ( f ) => f . id ) )
167- ) ;
166+
167+ let flowSearchIds = new Set < FlowId > ( ) ;
168+ if ( isFilterByFlowObjects ) {
169+ flowSearchIds = intersectExclusiveSets (
170+ intersectCandidates ,
171+ new Set ( flowsFromObjectFilters . flows . map ( ( f ) => f . id ) )
172+ ) ;
173+ } else {
174+ flowSearchIds = intersectSets (
175+ intersectCandidates ,
176+ new Set ( flowsFromObjectFilters . flows . map ( ( f ) => f . id ) )
177+ ) ;
178+ }
168179
169180 const orderByForFlow = mapFlowOrderBy ( orderBy ) ;
170181
@@ -189,20 +200,6 @@ export class SearchFlowByFiltersStrategy implements FlowSearchStrategy {
189200 }
190201 const sortByFlowIDs = await sortByFlowIDsPromise ;
191202
192- // If 'includeChildrenOfParkedFlows' is defined and true
193- // we need to obtain the flowIDs from the children whose parent flows are parked
194- if ( shouldIncludeChildrenOfParkedFlows ) {
195- const children =
196- await this . flowService . getParkedParentsChildrenByFlowObjectFilter (
197- models ,
198- flowSearchIds
199- ) ;
200-
201- for ( const child of children ) {
202- flowsFromObjectFilters . flows . push ( child ) ;
203- sortByFlowIDs . push ( child ) ;
204- }
205- }
206203 // First check if we have created the promises
207204 // and if so, check if the flows are empty
208205 // If they are empty, we can return an empty array
@@ -277,6 +274,20 @@ export class SearchFlowByFiltersStrategy implements FlowSearchStrategy {
277274 }
278275 const parsedSortedFlows = parseFlowIdVersionSet ( sortedFlows ) ;
279276
277+ // If 'includeChildrenOfParkedFlows' is defined and true
278+ // we need to obtain the flowIDs from the children whose parent flows are parked
279+ if ( shouldIncludeChildrenOfParkedFlows ) {
280+ const children =
281+ await this . flowService . getParkedParentsChildrenByFlowObjectFilter (
282+ models ,
283+ flowSearchIds
284+ ) ;
285+
286+ for ( const child of children ) {
287+ parsedSortedFlows . push ( child ) ;
288+ }
289+ }
290+
280291 const count = sortedFlows . size ;
281292 const flows = await this . flowService . progresiveSearch (
282293 models ,
0 commit comments