Skip to content

Commit 17183f0

Browse files
Pl217manelcecs
authored andcommitted
TODO: Rewrite this with strong typing
1 parent d81d15c commit 17183f0

File tree

1 file changed

+11
-4
lines changed
  • src/domain-services/flows/strategy/impl

1 file changed

+11
-4
lines changed

src/domain-services/flows/strategy/impl/utils.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { type FlowId } from '@unocha/hpc-api-core/src/db/models/flow';
33
import { Cond, Op } from '@unocha/hpc-api-core/src/db/util/conditions';
44
import type { InstanceDataOf } from '@unocha/hpc-api-core/src/db/util/model-definition';
55
import { type InstanceOfModel } from '@unocha/hpc-api-core/src/db/util/types';
6+
import { objectEntries } from '@unocha/hpc-api-core/src/util';
67
import { createBrandedValue } from '@unocha/hpc-api-core/src/util/types';
78
import type * as t from 'io-ts';
89
import { type OrderBy } from '../../../../utils/database-types';
@@ -179,12 +180,17 @@ export const prepareFlowConditions = (
179180
): FlowWhere => {
180181
let flowConditions: FlowWhere = { ...defaultSearchFlowFilter };
181182

183+
// Cannot be undefined according to type
182184
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
184187
if (value !== undefined) {
185188
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 };
188194
} else {
189195
const typedKey = key as keyof FlowWhere;
190196
flowConditions = { ...flowConditions, [typedKey]: value };
@@ -193,7 +199,8 @@ export const prepareFlowConditions = (
193199
}
194200
}
195201

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;
197204
};
198205

199206
export const mergeUniqueEntities = (

0 commit comments

Comments
 (0)