-
Notifications
You must be signed in to change notification settings - Fork 1
/
SchedulesManager.js
64 lines (57 loc) · 1.59 KB
/
SchedulesManager.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
const FBService = require("./NetworkLayer/FBServices");
const GTApi = require("./NetworkLayer/GTApi");
const _ = require("lodash");
updateActiveSchedule = async turn => {
try {
const schedule = await FBService.getTurnSchedule(turn);
await FBService.updateActiveSchedule(schedule);
} catch (error) {
console.log(error);
}
};
updateTodaySchedule = async () => {
try {
await FBService.verifyTodaySchedule();
const yesterdaySchedule = await FBService.getYesterdarSchedule();
await FBService.updateTodaySchedule(yesterdaySchedule);
} catch (error) {
console.log(error);
}
};
updateRoutes = async () => {
try {
const geofences = await GTApi.fetchGeofences();
const routes = convertGeofencesToRoutes(geofences);
await FBService.updateRoutes(routes);
} catch (error) {
console.log(error);
}
};
updateTrucks = async () => {
try {
const devices = await GTApi.fetchDevices();
const trucks = convertDevicesToTruckData(devices);
await FBService.updateTrucks(trucks);
} catch (error) {
console.log(error);
}
};
convertDevicesToTruckData = devices => {
modifiedDevices = _.map(devices, device => {
return { id: device.id, nombre: device.name };
});
return _.keyBy(modifiedDevices, "id");
};
convertGeofencesToRoutes = geofences => {
modifiedGeofences = _.map(geofences, geofence => {
return { id: geofence.id, comment: geofence.comment, name: geofence.name };
});
return _.keyBy(modifiedGeofences, "id");
};
module.exports = {
updateActiveSchedule,
updateRoutes,
updateActiveSchedule,
updateTodaySchedule,
updateTrucks
};