feat(medusa, medusa-js, medusa-react): Implement Sales Channel list (#1815)
**What** Support sales channel list in medusa, medusa-js and medusa-react **How** By implementing a new endpoint and the associated service method as well as the repository methods. Medusa-js new list method in the resource Medusa-react new hook in the queries **Tests** Endpoint test Service test Integration test Hook tests Fixes CORE-280
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { removeUndefinedProperties } from "../remove-undefined-properties";
|
||||
|
||||
describe("removeUndefinedProperties", () => {
|
||||
it("should remove all undefined properties from an input object", () => {
|
||||
const inputObj = {
|
||||
test: undefined,
|
||||
test1: "test1",
|
||||
test2: null,
|
||||
test3: {
|
||||
test3_1: undefined,
|
||||
test3_2: "test3_2",
|
||||
test3_3: null,
|
||||
},
|
||||
test4: [
|
||||
undefined,
|
||||
null,
|
||||
"null",
|
||||
[1, 2, undefined],
|
||||
{
|
||||
test4_1: undefined,
|
||||
test4_2: "test4_2",
|
||||
test4_3: null,
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
const cleanObject = removeUndefinedProperties(inputObj)
|
||||
|
||||
expect(cleanObject).toEqual({
|
||||
test1: "test1",
|
||||
test2: null,
|
||||
test3: {
|
||||
test3_2: "test3_2",
|
||||
test3_3: null,
|
||||
},
|
||||
test4: [
|
||||
null,
|
||||
null,
|
||||
[1, 2],
|
||||
{
|
||||
test4_2: "test4_2",
|
||||
test4_3: null
|
||||
}
|
||||
]
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './build-query'
|
||||
export * from './set-metadata'
|
||||
export * from './validate-id'
|
||||
export * from './generate-entity-id'
|
||||
export * from "./build-query"
|
||||
export * from "./set-metadata"
|
||||
export * from "./validate-id"
|
||||
export * from "./generate-entity-id"
|
||||
export * from "./remove-undefined-properties"
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
export function removeUndefinedProperties<T extends object>(inputObj: T): T {
|
||||
const removeProperties = (obj: T) => {
|
||||
const res = {} as T
|
||||
|
||||
Object.keys(obj).reduce((acc: T, key: string) => {
|
||||
if (typeof obj[key] === "undefined") {
|
||||
return acc
|
||||
}
|
||||
acc[key] = removeUndefinedDeeply(obj[key])
|
||||
return acc
|
||||
}, res)
|
||||
|
||||
return res
|
||||
}
|
||||
|
||||
return removeProperties(inputObj)
|
||||
}
|
||||
|
||||
function removeUndefinedDeeply(input: unknown): any {
|
||||
if (typeof input !== "undefined") {
|
||||
if (input === null || input === "null") {
|
||||
return null
|
||||
} else if (Array.isArray(input)) {
|
||||
return input.map((item) => {
|
||||
return removeUndefinedDeeply(item)
|
||||
}).filter(v => typeof v !== "undefined")
|
||||
} else if (Object.prototype.toString.call(input) === '[object Date]') {
|
||||
return input
|
||||
} else if (typeof input === "object") {
|
||||
return Object.keys(input).reduce((acc: Record<string, unknown>, key: string) => {
|
||||
if (typeof input[key] === "undefined") {
|
||||
return acc
|
||||
}
|
||||
acc[key] = removeUndefinedDeeply(input[key])
|
||||
return acc
|
||||
}, {})
|
||||
} else {
|
||||
return input
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user