1 | import DataLoader from 'dataloader';
|
2 | import {
|
3 | getCloseUsersLocations,
|
4 | getDistanceLocation,
|
5 | getLocation,
|
6 | updateGeolocation,
|
7 | } from '../../Services/Geolocation';
|
8 |
|
9 |
|
10 | const getGeolocationsLoader = (cacheMap) => {
|
11 | const geolocationsLoader =
|
12 | new DataLoader(params => Promise.all(params.map(getLocation)), { cache: false });
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | const geolocationsCloseUsersLoader =
|
20 | new DataLoader(params => Promise.all(params.map(getCloseUsersLocations)), { cache: false });
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | const geolocationsDistanceLoader =
|
28 | new DataLoader(params => Promise.all(params.map(getDistanceLocation)), { cache: false });
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | geolocationsLoader.load = geolocationsLoader.load.bind(geolocationsLoader);
|
36 | geolocationsLoader.loadCloseUsers = geolocationsCloseUsersLoader.load.bind(geolocationsCloseUsersLoader);
|
37 | geolocationsLoader.loadDistanceFromUser = geolocationsDistanceLoader.load.bind(geolocationsDistanceLoader);
|
38 | geolocationsLoader.updateGeolocation = updateGeolocation;
|
39 |
|
40 | return geolocationsLoader;
|
41 | };
|
42 |
|
43 | export default { getGeolocationsLoader };
|