Bedarfsausweis

This commit is contained in:
Moritz Utcke
2025-02-11 17:31:27 +07:00
parent c7b1bc7958
commit e3844c8684
5 changed files with 120 additions and 75 deletions

View File

@@ -2,26 +2,73 @@
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
import BedarfsausweisWohnenModule from "#modules/BedarfsausweisWohnen/BedarfsausweisWohnenModule.svelte";
import { BedarfsausweisWohnenClient } from "#components/Ausweis/types";
import { createCaller } from "#lib/caller";
import { AufnahmeClient, BedarfsausweisWohnenClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
import { createCaller } from "src/astro-typesafe-api-caller";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
const uid = Astro.url.searchParams.get("uid");
let ausweis: Partial<BedarfsausweisWohnenClient> = {
aufnahme: { objekt: {} },
energiequelle_2_nutzung: []
} as Partial<BedarfsausweisWohnenClient>;
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) {
ausweis = await caller.v1.bedarfsausweisWohen.get({
uid: uid,
});
if (!valid) {
return Astro.redirect(
`/auth/login?redirect=${Astro.url.toString()}`
);
}
if (!ausweis) {
// Der Ausweis scheint nicht zu existieren.
// Wir leiten auf die generische Ausweisseite ohne UID weiter.
try {
ausweis = await caller["bedarfsausweis-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.objekt._uid.bilder.GET.fetch(null, {
headers: {
authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
},
params: {
uid: ausweis.uid_objekt
}
})
if (!ausweis) {
// Der Ausweis scheint nicht zu existieren.
// Wir leiten auf die generische Ausweisseite ohne UID weiter.
return Astro.redirect(
"/energieausweis-erstellen/bedarfsausweis-wohnen"
);
}
} catch(e) {
return Astro.redirect(
"/energieausweis-erstellen/bedarfsausweis-wohnen"
);
@@ -31,5 +78,5 @@ if (uid) {
---
<AusweisLayout title="Bedarfsausweis erstellen | IBCornelsen">
<BedarfsausweisWohnenModule client:load ausweis={ausweis}></BedarfsausweisWohnenModule>
<BedarfsausweisWohnenModule client:load {ausweis} {objekt} {aufnahme} {bilder}></BedarfsausweisWohnenModule>
</AusweisLayout>