This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
forked from betagouv/annuaire-api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
v1.js
69 lines (64 loc) · 1.68 KB
/
v1.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
65
66
67
68
69
function toLegacyFeature (feature, lastUpdatedAt) {
let firstAddress
if (feature.properties.adresses.length > 0) {
firstAddress = feature.properties.adresses[0]
}
let address = {}
if (firstAddress) {
address = {
type: firstAddress.type,
Ligne: firstAddress.lignes.join(' '),
CodePostal: firstAddress.codePostal,
NomCommune: firstAddress.commune,
Localisation: {
Latitude: firstAddress.coordonnees[0],
Longitude: firstAddress.coordonnees[1],
Précision: '4' // FIXME Not sure where this is coming from
},
Accessibilité: {
type: 'ACC' // FIXME What is this?
}
}
}
let openings = []
if (feature.properties.horaires.length > 0) {
openings = feature.properties.horaires.map(opening => {
return {
début: opening.du,
fin: opening.au,
PlageH: opening.heures.map(hours => ({
début: hours.d,
fin: hours.a
}))
}
})
}
return {
...feature,
properties: {
...feature.properties,
Nom: feature.properties.nom,
EditeurSource: '',
dateMiseAJour: lastUpdatedAt,
Adresse: address,
CoordonnéesNum: {
Téléphone: feature.properties.telephone || '',
Télécopie: feature.properties.fax || '',
Email: feature.properties.email || ''
},
Ouverture: {
PlageJ: openings
}
}
}
}
function decorateLegacyResponse (featureCollection, lastUpdatedAt) {
return {
...featureCollection,
features: featureCollection.features.map(feature => toLegacyFeature(feature, lastUpdatedAt))
}
}
module.exports = {
toLegacyFeature,
decorateLegacyResponse
}