Automatische DWD Abfrage

Crontab hinzugefügt und automatische DWD Abfrage jeden Monat eingerichtet.
This commit is contained in:
Moritz Utcke
2024-01-06 15:42:59 +07:00
parent 30cc5fab63
commit dfd7cce6c8
9 changed files with 117 additions and 46 deletions

View File

@@ -1,6 +1,6 @@
import type { APIRoute } from "astro";
import moment from "moment";
import { ActionFailedError, InvalidDataError, MissingPropertyError, error, success } from "src/lib/APIResponse";
import { ActionFailedError, MissingPropertyError, error, success } from "src/lib/APIResponse";
import { getClimateFactor } from "src/lib/Klimafaktoren/getClimateFactor";
export const get: APIRoute = async function({ url }) {
@@ -45,11 +45,19 @@ export const get: APIRoute = async function({ url }) {
currentDate.add(1, accuracy);
}
const climateFactors = await getClimateFactor(intervals, zip);
const klimafaktoren = await getClimateFactor(intervals, zip);
if (!climateFactors) {
if (!klimafaktoren) {
return ActionFailedError();
}
return success(climateFactors);
if (klimafaktoren.length !== intervals.length) {
return error(["Not all dates could be found."]);
}
return success(klimafaktoren.map(klimafaktor => ({
month: klimafaktor.month,
year: klimafaktor.year,
klimafaktor: klimafaktor.klimafaktor,
})));
}