20 lines
574 B
JavaScript
20 lines
574 B
JavaScript
export async function fetchStations() {
|
|
const res = await fetch('/api/campagne_map_data');
|
|
if (!res.ok) throw new Error(`Errore HTTP ${res.status}`);
|
|
const geojson = await res.json();
|
|
return geojson.features
|
|
.map(f => ({ ...f.properties, pk: parseInt(f.properties.pk, 10) }))
|
|
.sort((a, b) => b.pk - a.pk);
|
|
}
|
|
|
|
export async function fetchDay(id, date) {
|
|
try {
|
|
const res = await fetch(`/api/get_measurements/${id}?day=${date}`);
|
|
if (!res.ok) return [];
|
|
const data = await res.json();
|
|
return data.misure ?? [];
|
|
} catch {
|
|
return [];
|
|
}
|
|
}
|