-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.js
More file actions
58 lines (48 loc) · 1.6 KB
/
functions.js
File metadata and controls
58 lines (48 loc) · 1.6 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Here usefull functions for work is presented
// obj which will store attribute keys according to attribute_type
/* {
"SERVER_SCOPE": ["active, "простой",.....],
"CLIENT_SCOPE": [...],
}
*/
function makeAttrsValuesObj(incomeAttrs){
let outputObj = {};
let buf = [];
for (let i = 0; i < incomeAttrs.length; i++) {
if (i === incomeAttrs.length - 1) {
buf.push(incomeAttrs[i])
outputObj[incomeAttrs[i].attribute_type] = buf;
break;
}
if (incomeAttrs[i].attribute_type === incomeAttrs[i + 1].attribute_type) {
buf.push(incomeAttrs[i]);
}
if (incomeAttrs[i].attribute_type !== incomeAttrs[i + 1].attribute_type) {
buf.push(incomeAttrs[i]);
outputObj[incomeAttrs[i].attribute_type] = buf;
buf = [];
}
}
return outputObj;
}
function updateChildAttrsKeysValue(incomeParentAttrs, childId, childType){
// childAttributes is parent attributes that not existed before in child
// before assign new attributes to child
// change entity_id, entity_type and etc.
// create deep copy
const childVals = JSON.parse(JSON.stringify(incomeParentAttrs));
for (let val of childVals) {
val.entity_id = childId;
val.entity_type = childType;
val.bool_v = null;
val.str_v = null;
val.long_v = null;
val.dbl_v = null;
val.last_update_ts = Date.now();
}
return childVals;
}
module.exports = {
makeAttrsValuesObj: makeAttrsValuesObj,
updateChildAttrsKeysValue: updateChildAttrsKeysValue,
}