feat(medusa): Improve buildQuery as well as refactor the cart service as an example

This commit is contained in:
adrien2p
2022-04-21 13:48:16 +02:00
parent e7e715ac17
commit b90291b18d
6 changed files with 86 additions and 69 deletions
+16 -3
View File
@@ -1,7 +1,20 @@
import { FindConfig, Writable } from "../types/common"
import {
DateComparisonOperator,
FindConfig,
NumericalComparisonOperator,
StringComparisonOperator,
Writable,
} from "../types/common"
import { FindOperator, In, Raw } from "typeorm"
type Selector<TEntity> = { [key in keyof TEntity]?: unknown }
type Selector<TEntity> = {
[key in keyof TEntity]?: TEntity[key]
| TEntity[key][]
| DateComparisonOperator
| StringComparisonOperator
| NumericalComparisonOperator
}
/**
* Used to build TypeORM queries.
* @param selector The selector
@@ -16,7 +29,7 @@ export function buildQuery<TEntity = unknown>(
withDeleted?: boolean
} {
const build = (
obj: Record<string, unknown>
obj: Selector<TEntity>
): Partial<Writable<TEntity>> => {
return Object.entries(obj).reduce((acc, [key, value]: any) => {
// Undefined values indicate that they have no significance to the query.