-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
94 lines (85 loc) · 2.19 KB
/
server.js
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
85
86
87
88
89
90
91
92
93
94
const express = require('express');
const _map = require('lodash/fp/map');
const _capitalize = require('lodash/fp/capitalize');
const _split = require('lodash/fp/split');
const _join = require('lodash/fp/join');
const _compose = require('lodash/fp/compose');
const _compact = require('lodash/fp/compact');
const app = express();
const port = 4000;
const employees = {
'John Hartman': {
name: 'John Hartman',
position: 'CEO',
directSubordinates: () => [
employees['Samad Pitt'].name,
employees['Leanna Hogg'].name,
],
},
'Samad Pitt': {
name: 'Samad Pitt',
position: 'production supervisor',
directSubordinates: () => [
employees['Aila Hodgson'].name,
employees['Amaya Knight'].name,
],
},
'Leanna Hogg': {
name: 'Leanna Hogg',
position: 'marketing supervisor',
directSubordinates: () => [
employees['Vincent Todd'].name,
employees['Faye Oneill'].name,
employees['Lynn Haigh'].name,
employees['Aila Hodgson'].name,
],
},
'Aila Hodgson': {
name: 'Aila Hodgson',
position: 'employee',
},
'Amaya Knight': {
name: 'Amaya Knight',
position: 'employee',
},
'Vincent Todd': {
name: 'Vincent Todd',
position: 'employee',
},
'Faye Oneill': {
name: 'Faye Oneill',
position: 'employee',
},
'Lynn Haigh': {
name: 'Lynn Haigh',
position: 'marketing supervisor',
directSubordinates: () => [employees['Nylah Riddle'].name],
},
'Nylah Riddle': {
name: 'Nylah Riddle',
position: 'employee',
},
};
const capitalizeEachWord = _map(_capitalize);
app.get('/employees', (req, res) => {
res.json(_map('name', employees));
});
app.get('/employees/:employeeName', (req, res) => {
const { employeeName } = req.params;
const employeeDetails =
employees[
_compose(_join(' '), capitalizeEachWord, _split(' '))(employeeName)
];
if (!employeeDetails) {
return res.json({});
}
res.json(
_compact([
employeeDetails.position,
employeeDetails.directSubordinates && {
'direct-subordinates': employeeDetails.directSubordinates(),
},
]),
);
});
app.listen(port, () => console.log(`Server listening on port ${port}!`));