Bildupload - UI - Globaler Ausweis

This commit is contained in:
Moritz Utcke
2023-05-08 16:35:36 +04:00
parent 7e13a6da50
commit 2c2c69f2d3
21 changed files with 452 additions and 343 deletions

View File

@@ -0,0 +1,16 @@
import type { APIRoute } from "astro";
import { success } from "src/lib/APIResponse";
/**
* Erstellt einen Verbrauchsausweis anhand der gegebenen Daten und trägt ihn in die Datenbank ein.
* @param param0
* @returns
*/
export const post: APIRoute = async ({ request }) => {
const body = await request.json();
return success({});
}

View File

@@ -4,10 +4,15 @@ import { ActionFailedError, InvalidDataError, MissingPropertyError, error, succe
import { getClimateFactor } from "src/lib/Klimafaktoren/getClimateFactor";
export const get: APIRoute = async function({ request }) {
const body = Object.fromEntries(new URLSearchParams(request.url.split("?")[1]))
let body;
try {
body = Object.fromEntries(new URLSearchParams(request.url.split("?")[1]))
} catch(e) {
return error(["Failed to parse URL"]);
}
if (!body.start || !body.end) {
return MissingPropertyError(["start", "end"]);
if (!body.date) {
return MissingPropertyError(["date"]);
}
let accuracy = body.accuracy || "months";
@@ -20,8 +25,8 @@ export const get: APIRoute = async function({ request }) {
return error(["Invalid ZIP Code, must be 4 or 5 characters long."])
}
let start = moment(body.start);
let end = moment(body.end);
let start = moment(body.date);
let end = moment(body.date).add("2", "years");
if (!start.isValid()) {
return error(["Invalid start date given."]);