-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'only-flow-conditions-strategy' implementation
Add also utils to operate over flows
- Loading branch information
Showing
2 changed files
with
438 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
src/domain-services/flows/strategy/impl/only-flow-conditions-strategy-impl.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Cond, Op } from '@unocha/hpc-api-core/src/db/util/conditions'; | ||
import { Service } from 'typedi'; | ||
import { FlowService } from '../../flow-service'; | ||
import { | ||
type FlowSearchArgs, | ||
type FlowSearchStrategy, | ||
type FlowSearchStrategyResponse, | ||
} from '../flow-search-strategy'; | ||
import { | ||
mapFlowOrderBy, | ||
prepareFlowConditions, | ||
prepareFlowStatusConditions, | ||
} from './utils'; | ||
|
||
@Service() | ||
export class OnlyFlowFiltersStrategy implements FlowSearchStrategy { | ||
constructor(private readonly flowService: FlowService) {} | ||
|
||
async search(args: FlowSearchArgs): Promise<FlowSearchStrategyResponse> { | ||
const { | ||
databaseConnection, | ||
models, | ||
flowFilters, | ||
orderBy, | ||
limit, | ||
offset, | ||
statusFilter, | ||
} = args; | ||
// Map flowConditions to where clause | ||
let flowConditions = prepareFlowConditions(flowFilters); | ||
|
||
// Add status filter conditions if provided | ||
flowConditions = prepareFlowStatusConditions(flowConditions, statusFilter); | ||
|
||
// Build conditions object | ||
// We need to add the condition to filter the deletedAt field | ||
const whereClause = { | ||
[Cond.AND]: [ | ||
{ | ||
deletedAt: { | ||
[Op.IS_NULL]: true, | ||
}, | ||
}, | ||
flowConditions ?? {}, | ||
], | ||
}; | ||
|
||
const orderByFlow = mapFlowOrderBy(orderBy); | ||
|
||
const [flows, countRes] = await Promise.all([ | ||
this.flowService.getFlows({ | ||
models, | ||
conditions: whereClause, | ||
offset, | ||
orderBy: orderByFlow, | ||
limit, | ||
}), | ||
this.flowService.getFlowsCount(databaseConnection, whereClause), | ||
]); | ||
|
||
// Map count result query to count object | ||
const countObject = countRes; | ||
|
||
return { flows, count: countObject }; | ||
} | ||
} |
Oops, something went wrong.