94 lines
2.8 KiB
Plaintext
94 lines
2.8 KiB
Plaintext
---
|
|
|
|
import KundendatenModule from "#modules/KundendatenModule.svelte";
|
|
import AusweisLayout from "#layouts/AusweisLayoutPruefung.astro";
|
|
import { Enums } from "@ibcornelsen/database/client";
|
|
import { createCaller } from "../astro-typesafe-api-caller";
|
|
import { API_ACCESS_TOKEN_COOKIE_NAME, API_REFRESH_TOKEN_COOKIE_NAME } from "#lib/constants";
|
|
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
|
import { BedarfsausweisWohnenClient, getAusweisartFromUUID, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
|
|
|
// Man sollte nur auf diese Seite kommen, wenn ein Ausweis bereits vorliegt und in der Datenbank abgespeichert wurde.
|
|
const uid = Astro.url.searchParams.get("uid");
|
|
const valid = await validateAccessTokenServer(Astro)
|
|
|
|
if (!uid || !valid) {
|
|
return Astro.redirect("/404");
|
|
}
|
|
|
|
|
|
const caller = createCaller(Astro)
|
|
|
|
const ausweisart = getAusweisartFromUUID(uid);
|
|
|
|
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient;
|
|
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
|
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid
|
|
}
|
|
})
|
|
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
|
ausweis = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid
|
|
}
|
|
})
|
|
} else if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) {
|
|
ausweis = await caller["bedarfsausweis-wohnen"]._uid.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid
|
|
}
|
|
})
|
|
} else {
|
|
return Astro.redirect("/404")
|
|
}
|
|
|
|
const aufnahme = await caller.aufnahme._uid.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid: ausweis.uid_aufnahme
|
|
}
|
|
})
|
|
|
|
const objekt = await caller.objekt._uid.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
},
|
|
params: {
|
|
uid: aufnahme.uid_objekt
|
|
}
|
|
})
|
|
|
|
const user = await caller.user.self.GET.fetch(undefined, {
|
|
headers: {
|
|
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
|
}
|
|
});
|
|
|
|
aufnahme.ausweisart = "VerbrauchsausweisWohnen"
|
|
|
|
|
|
|
|
|
|
if (!ausweis || !user) {
|
|
return Astro.redirect("/404");
|
|
}
|
|
---
|
|
|
|
<AusweisLayout title="Kundendaten Aufnehmen - IBCornelsen">
|
|
<KundendatenModule {user} {ausweis} {objekt} {aufnahme} {ausweisart} bezahlmethode={Enums.Bezahlmethoden.paypal} client:load></KundendatenModule>
|
|
</AusweisLayout>
|
|
|