81 lines
2.3 KiB
Plaintext
81 lines
2.3 KiB
Plaintext
---
|
|
import AusweisLayoutImmowelt from "#layouts/AusweisLayoutDatenImmowelt.astro";
|
|
import VerbrauchsausweisWohnenModule from "#modules/VerbrauchsausweisWohnen/VerbrauchsausweisWohnenModule.svelte";
|
|
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
|
import { createCaller } from "../../astro-typesafe-api-caller.js";
|
|
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
|
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
|
|
|
const uid = Astro.url.searchParams.get("uid");
|
|
let ausweis: VerbrauchsausweisWohnenClient = {} as VerbrauchsausweisWohnenClient;
|
|
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
|
let objekt: ObjektClient = {} as ObjektClient;
|
|
let bilder: UploadedGebaeudeBild[] = []
|
|
|
|
const valid = validateAccessTokenServer(Astro);
|
|
|
|
const caller = createCaller(Astro);
|
|
|
|
if (uid) {
|
|
if (!valid) {
|
|
return Astro.redirect(
|
|
`/auth/login?redirect=${Astro.url.toString()}`
|
|
);
|
|
}
|
|
|
|
try {
|
|
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(null, {
|
|
headers: {
|
|
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid
|
|
}
|
|
});
|
|
|
|
aufnahme = await caller.aufnahme._uid.GET.fetch(null, {
|
|
headers: {
|
|
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid: ausweis.uid_aufnahme
|
|
}
|
|
})
|
|
|
|
objekt = await caller.objekt._uid.GET.fetch(null, {
|
|
headers: {
|
|
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid: ausweis.uid_objekt
|
|
}
|
|
})
|
|
|
|
bilder = await caller.aufnahme._uid.bilder.GET.fetch(null, {
|
|
headers: {
|
|
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid: ausweis.uid_aufnahme
|
|
}
|
|
})
|
|
|
|
if (!ausweis) {
|
|
// Der Ausweis scheint nicht zu existieren.
|
|
// Wir leiten auf die generische Ausweisseite ohne UID weiter.
|
|
return Astro.redirect(
|
|
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
|
);
|
|
}
|
|
} catch(e) {
|
|
return Astro.redirect(
|
|
"/energieausweis-erstellen/verbrauchsausweis-wohngebaeude"
|
|
);
|
|
}
|
|
}
|
|
---
|
|
|
|
<AusweisLayoutImmowelt title="Verbrauchsausweis erstellen">
|
|
<VerbrauchsausweisWohnenModule client:load {ausweis} {objekt} {aufnahme} {bilder} />
|
|
</AusweisLayoutImmowelt>
|