feat(core-flows,medusa,utils): promotion and campaign create/update endpoint (#6130)
what: - adds create endpoint for promotions including workflows and endpoint (RESOLVES CORE-1678) - adds update endpoint for promotions including workflows and endpoint (RESOLVES CORE-1679) - adds create endpoint for campaigns including workflows and endpoint (RESOLVES CORE-1684) - adds update endpoint for campaigns including workflows and endpoint (RESOLVES CORE-1685)
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { deduplicate } from "./deduplicate"
|
||||
import { isObject } from "./is-object"
|
||||
|
||||
export function getSelectsAndRelationsFromObjectArray(
|
||||
dataArray: object[],
|
||||
prefix?: string
|
||||
): {
|
||||
selects: string[]
|
||||
relations: string[]
|
||||
} {
|
||||
const selects: string[] = []
|
||||
const relations: string[] = []
|
||||
|
||||
for (const data of dataArray) {
|
||||
for (const [key, value] of Object.entries(data)) {
|
||||
if (isObject(value)) {
|
||||
relations.push(setKey(key, prefix))
|
||||
const res = getSelectsAndRelationsFromObjectArray(
|
||||
[value],
|
||||
setKey(key, prefix)
|
||||
)
|
||||
selects.push(...res.selects)
|
||||
relations.push(...res.relations)
|
||||
} else if (Array.isArray(value)) {
|
||||
relations.push(setKey(key, prefix))
|
||||
const res = getSelectsAndRelationsFromObjectArray(
|
||||
value,
|
||||
setKey(key, prefix)
|
||||
)
|
||||
selects.push(...res.selects)
|
||||
relations.push(...res.relations)
|
||||
} else {
|
||||
selects.push(setKey(key, prefix))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const uniqueSelects: string[] = deduplicate(selects)
|
||||
const uniqueRelations: string[] = deduplicate(relations)
|
||||
|
||||
return {
|
||||
selects: uniqueSelects,
|
||||
relations: uniqueRelations,
|
||||
}
|
||||
}
|
||||
|
||||
function setKey(key: string, prefix?: string) {
|
||||
if (prefix) {
|
||||
return `${prefix}.${key}`
|
||||
} else {
|
||||
return key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user