26 lines
634 B
TypeScript
26 lines
634 B
TypeScript
import moment from "moment";
|
|
import { memoize } from "./Memoization.js";
|
|
import { api } from "astro-typesafe-api/client"
|
|
|
|
export const getKlimafaktoren = memoize(async (date: Date, plz: string) => {
|
|
if (!plz || !date) {
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
const response = await api.klimafaktoren.GET.fetch({
|
|
plz,
|
|
genauigkeit: "years",
|
|
// @ts-ignore Der Adapter nimmt z.coerce.date()
|
|
startdatum: moment(date).utc(true).toString(),
|
|
// @ts-ignore Der Adapter nimmt z.coerce.date()
|
|
enddatum: moment(date).add(2, "years").utc(true).toString(),
|
|
});
|
|
return response;
|
|
} catch (e) {
|
|
console.log(e);
|
|
|
|
return null;
|
|
}
|
|
});
|