feat(medusa): Improve buildQuery as well as refactor the cart service as an example
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export * from './build-query'
|
||||
export * from './set-metadata'
|
||||
export * from './validate-id'
|
||||
@@ -6,7 +6,7 @@ import { MedusaError } from "medusa-core-utils/dist"
|
||||
* @param metadata - the metadata to set
|
||||
* @return resolves to the updated result.
|
||||
*/
|
||||
export function setMetadata_(
|
||||
export function setMetadata(
|
||||
obj: { metadata: Record<string, unknown> },
|
||||
metadata: Record<string, unknown>
|
||||
): Record<string, unknown> {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
import { MedusaError } from "medusa-core-utils/dist"
|
||||
|
||||
export function validateId_(
|
||||
export function validateId(
|
||||
rawId: string,
|
||||
config: { prefix?: string; length?: number } = {}
|
||||
): string {
|
||||
|
||||
Reference in New Issue
Block a user