Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
84 lines (71 loc) · 2 KB
/
Copy pathindex.js
File metadata and controls
84 lines (71 loc) · 2 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* Example problem with existing solution and passing test.
* See problem 0 in the spec file for the assertion
* @returns {string}
*/
exports.example = () => 'hello world';
exports.stripPrivateProperties = (keys,objects) => {
return Array.from(objects).map((obj)=>{
return Object.keys(obj)
.filter(k=>keys.indexOf(k) < 0)
.reduce((pre,curr)=>{
return {...pre,[curr]:obj[curr]}
},{})
})
};
exports.excludeByProperty = (excludeKey,objects) => {
return objects.filter((obj)=>{
return Object.keys(obj)
.indexOf(excludeKey) < 0
})
};
exports.sumDeep = (objects) => {
return objects.map((obj)=>{
return {
objects:Array.from(obj.objects).reduce((pre,curr)=>{
return pre + curr.val
},0)
}
})
};
exports.applyStatusColor = (colorObj,objects) => {
const colorMap = Object.keys(colorObj).reduce((pre,curr)=>{
return {...pre,...colorObj[curr].reduce((p,c)=>{
return {
...p,
[c]:curr
}
},{})}
},{})
return objects.filter(x=>colorMap[x.status]).map((obj)=>{
return {
...obj
,color:colorMap[obj.status]
}
})
};
exports.createGreeting = (fn,greeting) => {
return function(name){
return fn(greeting,name)
}
};
exports.setDefaults = (defaults) => {
return (obj)=>{
return {
...defaults,
...obj
}
}
};
exports.fetchUserByNameAndUsersCompany = (name,services) => {
return new Promise(async(resolve,reject) =>{
const user = (await services.fetchUsers()).filter(u=>u.name == name)[0]
const company = await services.fetchCompanyById(user.companyId)
const status = await services.fetchStatus()
resolve({
company,
status,
user
})
})
};