-
Notifications
You must be signed in to change notification settings - Fork 0
/
getEmployeesCoverage.js
53 lines (45 loc) · 1.36 KB
/
getEmployeesCoverage.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
const {
employees,
species,
} = require('../data/zoo_data');
const data = require('../data/zoo_data');
function employee(worker) {
return employees.find((employee1) => employee1.firstName === worker.name
|| employee1.lastName === worker.name || employee1.id === worker.id);
}
function specie(worker) {
return species.filter((specie1) => {
if (!worker) {
throw new Error('Informações inválidas');
}
return worker.responsibleFor.includes(specie1.id);
});
}
function allEmployees() {
return employees.map((employee2) => {
const speciesArray = specie(employee2);
return {
id: employee2.id,
fullName: `${employee2.firstName} ${employee2.lastName}`,
species: speciesArray.map((element) => element.name),
locations: speciesArray.map((element) => element.location),
};
});
}
function getEmployeesCoverage(worker) {
if (!worker) {
return allEmployees();
}
const employeeObject = employee(worker);
const speciesArray = specie(employeeObject);
return {
id: employeeObject.id,
fullName: `${employeeObject.firstName} ${employeeObject.lastName}`,
species: speciesArray.map((element) => element.name),
locations: speciesArray.map((element) => element.location),
};
}
console.log(getEmployeesCoverage({
id: 'c1f50212-35a6-4ecd-8223-f835538526c2',
}));
module.exports = getEmployeesCoverage;