@@ -3,6 +3,7 @@ import { type FlowId } from '@unocha/hpc-api-core/src/db/models/flow';
3
3
import { Cond , Op } from '@unocha/hpc-api-core/src/db/util/conditions' ;
4
4
import type { InstanceDataOf } from '@unocha/hpc-api-core/src/db/util/model-definition' ;
5
5
import { type InstanceOfModel } from '@unocha/hpc-api-core/src/db/util/types' ;
6
+ import { objectEntries } from '@unocha/hpc-api-core/src/util' ;
6
7
import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types' ;
7
8
import type * as t from 'io-ts' ;
8
9
import { type OrderBy } from '../../../../utils/database-types' ;
@@ -179,12 +180,17 @@ export const prepareFlowConditions = (
179
180
) : FlowWhere => {
180
181
let flowConditions : FlowWhere = { ...defaultSearchFlowFilter } ;
181
182
183
+ // Cannot be undefined according to type
182
184
if ( flowFilters ) {
183
- for ( const [ key , value ] of Object . entries ( flowFilters ) ) {
185
+ for ( const [ key , value ] of objectEntries ( flowFilters ) ) {
186
+ // Cannot be undefined according to type
184
187
if ( value !== undefined ) {
185
188
if ( key === 'id' ) {
186
- const brandedIDs = value . map ( ( id : number ) => createBrandedValue ( id ) ) ;
187
- flowConditions [ key ] = { [ Op . IN ] : brandedIDs } ;
189
+ // If `key` is `'id'`, then we know the type of this (`FlowId[] | null`)
190
+ const flowIds = value as SearchFlowsFilters [ 'id' ] ;
191
+ // @ts -ignore
192
+ // Type error, can be `null`
193
+ flowConditions [ key ] = { [ Op . IN ] : flowIds } ;
188
194
} else {
189
195
const typedKey = key as keyof FlowWhere ;
190
196
flowConditions = { ...flowConditions , [ typedKey ] : value } ;
@@ -193,7 +199,8 @@ export const prepareFlowConditions = (
193
199
}
194
200
}
195
201
196
- return flowConditions satisfies FlowWhere ;
202
+ // It's of type `FlowWhere` already. No need for `satisfies`, return type of function does type-checking already
203
+ return flowConditions ;
197
204
} ;
198
205
199
206
export const mergeUniqueEntities = (
0 commit comments