Completed
Push — master ( f1da37...c68c1b )
by Mark
15s queued 11s
created

src/Util/Obj/fromModel.ts   A

Complexity

Total Complexity 11
Complexity/F 5.5

Size

Lines of Code 25
Function Count 2

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 25
rs 10
c 0
b 0
f 0
wmc 11
mnd 9
bc 9
fnc 2
bpm 4.5
cpm 5.5
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
C fromModel.ts ➔ arrayToObjects 0 5 11
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
}