Total Complexity | 11 |
Complexity/F | 5.5 |
Lines of Code | 25 |
Function Count | 2 |
Duplicated Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import Field from "../../Store/Model/Field"; |
||
2 | import Relation from "../../Store/Model/Relation"; |
||
3 | |||
4 | export default function (model, fromRelation = false) { |
||
5 | const json = {}; |
||
6 | |||
7 | for (let i = 0; i < model.originalFields.length; i++) { |
||
8 | const field = model.originalFields[i]; |
||
9 | if (field instanceof Relation && fromRelation) { |
||
10 | continue |
||
11 | } |
||
12 | json[field.name] = field?.value; |
||
13 | if (Array.isArray(json[field.name])) { |
||
14 | json[field.name] = arrayToObjects(json, field); |
||
15 | } |
||
16 | } |
||
17 | |||
18 | return {...json}; |
||
19 | } |
||
20 | |||
21 | function arrayToObjects(json: object, field: Field): Array<unknown> { |
||
22 | return [...json[field.name].map((value) => { |
||
23 | return (value?.toObject(true) ?? value) |
||
24 | }) ?? []]; |
||
25 | } |