-
Notifications
You must be signed in to change notification settings - Fork 727
Expand file tree
/
Copy pathconvert-nested-param.ts
More file actions
39 lines (32 loc) · 1.09 KB
/
convert-nested-param.ts
File metadata and controls
39 lines (32 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { BasePropertyJSON } from '../../frontend/interfaces/property-json/property-json.interface.js'
import { DELIMITER } from './constants.js'
import { convertParam } from './convert-param.js'
const convertNestedParam = (
parentValue: Record<string, any>,
subProperty: BasePropertyJSON,
): Record<string, any> => {
const path = subProperty.propertyPath.split(DELIMITER).slice(-1)[0]
const { type = 'string' } = subProperty
let value = parentValue[path]
if (type === 'mixed' && value) {
const nestedSubProperties = subProperty.subProperties
for (const nestedSubProperty of nestedSubProperties) {
if (subProperty.isArray) {
value = [...value].map((element) => convertNestedParam(element, nestedSubProperty))
} else {
value = convertNestedParam(value, nestedSubProperty)
}
}
} else {
if (subProperty.isArray && Array.isArray(value)) {
value = value.map((v) => convertParam(v, type))
} else {
value = convertParam(value, subProperty.type)
}
}
return {
...parentValue,
[path]: value,
}
}
export { convertNestedParam }