93 lines
3.1 KiB
Plaintext
93 lines
3.1 KiB
Plaintext
---
|
|
import { AufnahmeClient, BenutzerClient, getAusweisartFromUUID, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
|
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
|
import { pdfDatenblattVerbrauchsausweisWohnen } from "#lib/pdf/pdfDatenblattVerbrauchsausweisWohnen";
|
|
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen";
|
|
import { Enums } from "@ibcornelsen/database/client";
|
|
import { createCaller } from "src/astro-typesafe-api-caller";
|
|
|
|
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 benutzer: 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 {
|
|
const uidAusweis = Astro.url.searchParams.get("uid");
|
|
|
|
if (!uidAusweis) {
|
|
return Astro.redirect("/404");
|
|
}
|
|
|
|
const ausweisart = getAusweisartFromUUID(uidAusweis)
|
|
|
|
const caller = createCaller(Astro);
|
|
|
|
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
|
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
|
|
params: {
|
|
uid: uidAusweis
|
|
},
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
}
|
|
});
|
|
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
|
ausweis = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(undefined, {
|
|
params: {
|
|
uid: uidAusweis
|
|
},
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
if (!ausweis) {
|
|
return Astro.redirect("/");
|
|
}
|
|
|
|
aufnahme = await caller.aufnahme._uid.GET.fetch(undefined, {
|
|
params: {
|
|
uid: ausweis.uid_aufnahme
|
|
},
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
}
|
|
});
|
|
|
|
objekt = await caller.objekt._uid.GET.fetch(undefined, {
|
|
params: {
|
|
uid: ausweis.uid_objekt
|
|
},
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
}
|
|
});
|
|
|
|
benutzer = await caller.user.self.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
}
|
|
});
|
|
}
|
|
|
|
const pdf = await pdfDatenblattVerbrauchsausweisWohnen(ausweis, aufnahme, objekt, benutzer);
|
|
|
|
|
|
return new Response(pdf, {
|
|
headers: {
|
|
"Content-Type": "application/pdf",
|
|
},
|
|
});
|
|
---
|