-
Notifications
You must be signed in to change notification settings - Fork 0
/
data.js
57 lines (49 loc) · 1.54 KB
/
data.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
import { getData } from '/src/modules/utils'
// Constants
import {
TARIEFDEEL,
SPECIFICATIES_PARKEERGEBIED,
GEO_PARKEERGARAGES,
} from './constants'
export default async function cleanData() {
// Destructure data after all three promises have been resolved
const [
tariefData,
geoData,
specsData
] = await getData([
TARIEFDEEL,
GEO_PARKEERGARAGES,
SPECIFICATIES_PARKEERGEBIED,
])
const mergedData = geoData
.map(location => {
// Merge specs and geo based on AreaId
const spec = specsData.find(spec => location.areaid === spec.areaid)
return { ...location, ...spec }
})
.map(entry => {
// Merge tarief, specs and geo based on AreaManagerId
const tarief = tariefData.find(tarief => entry.areamanagerid === tarief.areamanagerid)
return { ...entry, ...tarief }
})
.map(entry => ({
...entry,
wheelchairAccessible: Boolean(+entry.disabledaccess),
parkingCapacity: +entry.capacity,
chargingPointCapacity: +entry.chargingpointcapacity,
// Cost of parking for one hour.
hourlyCost: (entry.amountfarepart / entry.stepsizefarepart) * 60,
// The area ID of the parking zone.
areaManagerId: +entry.areamanagerid,
areaId: entry.areaid,
description: entry.areadesc,
location: {
latitude: +entry.location.latitude,
longitude: +entry.location.longitude,
humanReadableAdress: JSON.parse(entry.location.human_address || '{}'),
}
}))
// Return ✨utterly pristine✨ data
return mergedData
}