Bildupload - UI - Globaler Ausweis
This commit is contained in:
16
src/pages/api/ausweis/verbrauchsausweis.ts
Normal file
16
src/pages/api/ausweis/verbrauchsausweis.ts
Normal 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({});
|
||||
}
|
||||
@@ -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."]);
|
||||
Reference in New Issue
Block a user