feat(pricing,medusa,utils): added list + get endpoints for price lists (#6592)

what:

- brings back price list GET endpoints to v2 endpoints
This commit is contained in:
Riqwan Thamir
2024-03-07 04:52:31 +05:30
committed by GitHub
parent 531e9e1e94
commit 000eb61e33
23 changed files with 686 additions and 111 deletions

View File

@@ -31,8 +31,10 @@ export * from "./medusa-container"
export * from "./object-from-string-path"
export * from "./object-to-string-path"
export * from "./optional-numeric-serializer"
export * from "./pick-deep"
export * from "./pick-value-from-object"
export * from "./plurailze"
export * from "./prefix-array-items"
export * from "./promise-all"
export * from "./remote-query-object-from-string"
export * from "./remote-query-object-to-string"

View File

@@ -0,0 +1,63 @@
import { isObject } from "./is-object"
export function pickDeep<T extends object = object>(
input: object,
fields: Array<number | string>,
prefix: string = ""
): T {
if (!input) {
return input
}
return Object.entries(input).reduce((nextInput, [key, value]) => {
const fieldKey = withPrefix(key, prefix)
const fieldMatches = fields.includes(fieldKey)
const partialKeyMatch =
fields.filter((field) => field.toString().startsWith(`${fieldKey}.`))
.length > 0
const valueIsObject = isObject(value)
const valueIsArray = Array.isArray(value)
if (fieldMatches && (valueIsObject || valueIsArray)) {
nextInput[key] = value
return nextInput
}
if (!fieldMatches && !partialKeyMatch) {
return nextInput
}
if (valueIsArray) {
nextInput[key] = value.map((arrItem) => {
if (isObject(arrItem)) {
return pickDeep(arrItem, fields, withPrefix(key, prefix))
}
return arrItem
})
return nextInput
} else if (valueIsObject) {
if (Object.keys(value).length) {
nextInput[key] = pickDeep(value, fields, withPrefix(key, prefix))
}
return nextInput
}
if (fieldMatches) {
nextInput[key] = value
}
return nextInput
}, {} as T)
}
function withPrefix(key: string, prefix: string): string {
if (prefix.length) {
return `${prefix}.${key}`
} else {
return key
}
}

View File

@@ -0,0 +1,8 @@
/**
* Prefixes an array of strings with a specified string
* @param array
* @param prefix
*/
export function prefixArrayItems(array: string[], prefix: string): string[] {
return array.map((arrEl) => `${prefix}${arrEl}`)
}