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)
54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
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
|
|
}
|
|
}
|