Daily forecast fix?
This commit is contained in:
@@ -84,15 +84,16 @@ app.get('/api/hourly', async (req, res) => {
|
||||
|
||||
app.get('/api/daily', async (req, res) => {
|
||||
const {fields} = req.query;
|
||||
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0)).toISOString();
|
||||
const start = req.query.start || new Date(new Date().setHours(0, 0, 0, 0));
|
||||
let now = new Date();
|
||||
now.setHours(0, 0, 0, 0);
|
||||
now = now.toISOString();
|
||||
const end = req.query.end || new Date().toISOString();
|
||||
let next = new Date(now);
|
||||
next.setDate(now.getDate() + 1);
|
||||
const end = req.query.end || new Date();
|
||||
const coords = await getCoords();
|
||||
const [sensor, meteo] = await Promise.allSettled([
|
||||
now > start ? queryDaily(start, now) : Promise.resolve([]),
|
||||
getOpenMeteo(coords.latitude, coords.longitude, now, end),
|
||||
now > start ? queryDaily(start.toISOString(), now.toISOString()) : Promise.resolve([]),
|
||||
getOpenMeteo(coords.latitude, coords.longitude, (start.getTime() > next.getTime() ? start : next).toISOString(), end.toISOString()),
|
||||
]);
|
||||
const history = sensor.status === 'fulfilled' ? sensor.value : [];
|
||||
const forecast = meteo.status === 'fulfilled' ? meteo.value.daily : [];
|
||||
|
||||
Reference in New Issue
Block a user