Ansichtsausweis
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,35 +1,27 @@
|
||||
---
|
||||
import { AufnahmeClient, BenutzerClient, getAusweisartFromUUID, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen.js";
|
||||
import { Enums } from "@ibcornelsen/database/client";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller";
|
||||
import { APIRoute } from "astro";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
||||
|
||||
const base64Ausweis = Astro.url.searchParams.get("ausweis");
|
||||
const base64Aufnahme = Astro.url.searchParams.get("aufnahme");
|
||||
const base64Objekt = Astro.url.searchParams.get("objekt");
|
||||
const base64Bilder = Astro.url.searchParams.get("bilder");
|
||||
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||
let objekt: ObjektClient = {} as ObjektClient;
|
||||
let user: BenutzerClient = {} as BenutzerClient;
|
||||
let bilder: UploadedGebaeudeBild[] = []
|
||||
if (base64Ausweis && base64Aufnahme && base64Objekt && base64Bilder) {
|
||||
ausweis = JSON.parse(Buffer.from(base64Ausweis, "base64").toString("utf-8")) as VerbrauchsausweisWohnenClient;
|
||||
objekt = JSON.parse(Buffer.from(base64Objekt, "base64").toString("utf-8")) as ObjektClient;
|
||||
aufnahme = JSON.parse(Buffer.from(base64Aufnahme, "base64").toString("utf-8")) as AufnahmeClient;
|
||||
bilder = JSON.parse(Buffer.from(base64Bilder, "base64").toString("utf-8")) as UploadedGebaeudeBild[];
|
||||
} else {
|
||||
export const GET: APIRoute = async (Astro) => {
|
||||
const uidAusweis = Astro.url.searchParams.get("uid");
|
||||
|
||||
if (!uidAusweis) {
|
||||
return Astro.redirect("/404");
|
||||
return Astro.redirect("/404")
|
||||
}
|
||||
|
||||
const ausweisart = getAusweisartFromUUID(uidAusweis)
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
|
||||
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||
let objekt: ObjektClient = {} as ObjektClient;
|
||||
let user: BenutzerClient = {} as BenutzerClient;
|
||||
let bilder: UploadedGebaeudeBild[] = []
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
@@ -78,13 +70,44 @@ if (base64Ausweis && base64Aufnahme && base64Objekt && base64Bilder) {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
const pdf = await pdfVerbrauchsausweisWohnen(ausweis, aufnahme, objekt, bilder, user);
|
||||
|
||||
return new Response(pdf, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
const pdf = await pdfVerbrauchsausweisWohnen(ausweis, aufnahme, objekt, bilder, user);
|
||||
export const POST: APIRoute = async (Astro) => {
|
||||
const body = await Astro.request.text();
|
||||
const params = new URLSearchParams(body);
|
||||
|
||||
return new Response(pdf, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
---
|
||||
const caller = createCaller(Astro);
|
||||
|
||||
const ausweis = JSON.parse(params.get("ausweis"));
|
||||
const aufnahme = JSON.parse(params.get("aufnahme"));
|
||||
const objekt = JSON.parse(params.get("objekt"));
|
||||
const bilder = JSON.parse(params.get("bilder"));
|
||||
|
||||
let user: BenutzerClient = {};
|
||||
|
||||
try {
|
||||
user = await caller.user.self.GET.fetch(undefined, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
const pdf = await pdfVerbrauchsausweisWohnen(ausweis, aufnahme, objekt, bilder, user);
|
||||
|
||||
return new Response(pdf, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user