ZIP Suche + Kundendaten

This commit is contained in:
Moritz Utcke
2023-04-06 10:54:07 +04:00
parent 4647bebef4
commit 115cfffdc2
7 changed files with 416 additions and 342 deletions

28
src/pages/api/zip.ts Normal file
View File

@@ -0,0 +1,28 @@
import type { APIRoute } from "astro";
import { success, MissingPropertyError, MissingEntityError, InvalidDataError } from "../../lib/APIResponse";
import { ZIPInformation } from "src/lib/ZIPInformation";
/**
* Ruft einen Nutzer anhand seiner uid aus der Datenbank ab.
* @param param0 Die Request mit dem request body. Dieser enthält entweder eine uid mit der der Benutzer identifiziert werden kann.
*/
export const get: APIRoute = async ({ request }) => {
const body = Object.fromEntries(new URLSearchParams(request.url.split("?")[1]))
let result;
if (body.zip) {
result = await ZIPInformation.fromZipCode(body.zip)
} else if (body.city) {
result = await ZIPInformation.fromCity(body.city)
} else if (body.state) {
result = await ZIPInformation.fromState(body.state)
} else {
return MissingPropertyError(["Either 'state', 'city' or 'zip' have to exist in request body."])
}
if (!result) {
return MissingEntityError("zip info")
}
return success(result);
}