Login Popup zu Kundendaten bewegt
This commit is contained in:
@@ -3,98 +3,37 @@
|
||||
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";
|
||||
import { getCurrentUser } from "#lib/server/user";
|
||||
|
||||
// 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 user = await getCurrentUser(Astro) || {}
|
||||
|
||||
const params = new URLSearchParams(await Astro.request.text());
|
||||
|
||||
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 if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen) {
|
||||
ausweis = await caller["geg-nachweis-wohnen"]._uid.GET.fetch(undefined, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
},
|
||||
params: {
|
||||
uid
|
||||
}
|
||||
})
|
||||
} else {
|
||||
if (!params.has("ausweis") || !params.has("aufnahme") || !params.has("objekt") || !params.has("bilder") || !params.has("ausweisart")) {
|
||||
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
|
||||
let ausweis, aufnahme, objekt, ausweisart, bilder, ausweistyp;
|
||||
try {
|
||||
ausweis = JSON.parse(params.get("ausweis") || "")
|
||||
aufnahme = JSON.parse(params.get("aufnahme") || "")
|
||||
objekt = JSON.parse(params.get("objekt") || "")
|
||||
ausweisart = JSON.parse(params.get("ausweisart") || "") as Enums.Ausweisart;
|
||||
bilder = JSON.parse(params.get("bilder") || "");
|
||||
ausweistyp = JSON.parse(params.get("ausweistyp") || "") as Enums.AusweisTyp;
|
||||
|
||||
if (!ausweisart || !Object.keys(Enums.Ausweisart).includes(ausweisart) || !ausweistyp || !Object.keys(Enums.AusweisTyp).includes(ausweistyp)) {
|
||||
throw new Error()
|
||||
}
|
||||
})
|
||||
|
||||
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");
|
||||
} catch(e){
|
||||
return Astro.redirect("/404")
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
<AusweisLayout title="Kundendaten Aufnehmen - IBCornelsen">
|
||||
<KundendatenModule {user} {ausweis} {objekt} {aufnahme} {ausweisart} bezahlmethode={Enums.Bezahlmethoden.paypal} client:load></KundendatenModule>
|
||||
<KundendatenModule {user} {ausweis} {objekt} {aufnahme} {bilder} {ausweisart} {ausweistyp} aktiveBezahlmethode={Enums.Bezahlmethoden.paypal} client:load></KundendatenModule>
|
||||
</AusweisLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user