-
Notifications
You must be signed in to change notification settings - Fork 0
/
locations.js
43 lines (39 loc) · 965 Bytes
/
locations.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
const store = require('./locations-store-connector');
let geocodeApi;
if(process.env.GEOCODE_API === 'MAPBOX_API') {
geocodeApi = require('./mapbox-api-adapter');
} else {
geocodeApi = require('./google-api-adapter');
}
const addLocation = (address, callback) => {
geocodeApi(address, (res) => {
let response;
if(res.result) {
response = store.addLocation(res.response);
} else {
response = {
result: false,
response: 'Unable to find address.'
};
}
callback(response);
});
}
const deleteLocation = (id, callback) => {
const response = store.deleteLocation(id);
callback(response);
}
const editLocation = (payload, callback) => {
const response = store.editLocation(payload);
callback(response);
}
const getLocations = (callback) => {
const response = store.getLocations();
callback(response);
}
module.exports = {
addLocation ,
deleteLocation,
editLocation,
getLocations,
};