diff --git a/persistent/unterlagen/pln-7628272a-1a70-44fb-8c00-a6b5125153c4 b/persistent/unterlagen/pln-7628272a-1a70-44fb-8c00-a6b5125153c4 new file mode 100644 index 00000000..b7529163 Binary files /dev/null and b/persistent/unterlagen/pln-7628272a-1a70-44fb-8c00-a6b5125153c4 differ diff --git a/persistent/unterlagen/pln-9412f6f9-16b2-4c96-a612-d0b788b73df7 b/persistent/unterlagen/pln-9412f6f9-16b2-4c96-a612-d0b788b73df7 new file mode 100644 index 00000000..b7529163 Binary files /dev/null and b/persistent/unterlagen/pln-9412f6f9-16b2-4c96-a612-d0b788b73df7 differ diff --git a/persistent/unterlagen/pln-bc44e0e7-14e5-4112-b113-59f172c387a6 b/persistent/unterlagen/pln-bc44e0e7-14e5-4112-b113-59f172c387a6 new file mode 100644 index 00000000..aba7cc1d Binary files /dev/null and b/persistent/unterlagen/pln-bc44e0e7-14e5-4112-b113-59f172c387a6 differ diff --git a/persistent/unterlagen/pln-be301689-303e-4f78-b0f2-08cda642e8cf b/persistent/unterlagen/pln-be301689-303e-4f78-b0f2-08cda642e8cf new file mode 100644 index 00000000..b7529163 Binary files /dev/null and b/persistent/unterlagen/pln-be301689-303e-4f78-b0f2-08cda642e8cf differ diff --git a/persistent/unterlagen/pln-c86f7c42-55cd-4448-9830-4c41ce7b3815 b/persistent/unterlagen/pln-c86f7c42-55cd-4448-9830-4c41ce7b3815 new file mode 100644 index 00000000..b7529163 Binary files /dev/null and b/persistent/unterlagen/pln-c86f7c42-55cd-4448-9830-4c41ce7b3815 differ diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index 7e7e52d5..89b0edcb 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -4,9 +4,7 @@ export const createCaller = createCallerFactory({ "bild": await import("../src/pages/api/bild.ts"), "klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"), "postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"), - "auth/access-token": await import("../src/pages/api/auth/access-token.ts"), - "auth/forgot-password": await import("../src/pages/api/auth/forgot-password.ts"), - "auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"), + "unterlage": await import("../src/pages/api/unterlage.ts"), "admin/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"), "admin/bestellbestaetigung": await import("../src/pages/api/admin/bestellbestaetigung.ts"), "admin/erinnern": await import("../src/pages/api/admin/erinnern.ts"), @@ -14,6 +12,9 @@ export const createCaller = createCallerFactory({ "admin/post-ausstellen": await import("../src/pages/api/admin/post-ausstellen.ts"), "admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"), "aufnahme": await import("../src/pages/api/aufnahme/index.ts"), + "auth/access-token": await import("../src/pages/api/auth/access-token.ts"), + "auth/forgot-password": await import("../src/pages/api/auth/forgot-password.ts"), + "auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"), "bedarfsausweis-wohnen/[uid]": await import("../src/pages/api/bedarfsausweis-wohnen/[uid].ts"), "bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"), "bilder/[uid]": await import("../src/pages/api/bilder/[uid].ts"), @@ -27,11 +28,10 @@ export const createCaller = createCallerFactory({ "user/self": await import("../src/pages/api/user/self.ts"), "verbrauchsausweis-gewerbe/[uid]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[uid].ts"), "verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.ts"), - "webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"), "verbrauchsausweis-wohnen/[uid]": await import("../src/pages/api/verbrauchsausweis-wohnen/[uid].ts"), "verbrauchsausweis-wohnen": await import("../src/pages/api/verbrauchsausweis-wohnen/index.ts"), + "webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"), "aufnahme/[uid]/bilder": await import("../src/pages/api/aufnahme/[uid]/bilder.ts"), "aufnahme/[uid]": await import("../src/pages/api/aufnahme/[uid]/index.ts"), "objekt/[uid]": await import("../src/pages/api/objekt/[uid]/index.ts"), - "objekt/[uid]/unterlagen": await import("../src/pages/api/objekt/[uid]/unterlagen.ts"), }) \ No newline at end of file diff --git a/src/client/lib/helpers.ts b/src/client/lib/helpers.ts new file mode 100644 index 00000000..5e1e0c0a --- /dev/null +++ b/src/client/lib/helpers.ts @@ -0,0 +1,18 @@ +import { writable, Writable } from "svelte/store"; + +export function localStorageSync(initial: T, name: string, modifier: (stored: any) => T = (stored) => JSON.parse(stored), reverseModifier: (value: T) => string = (value) => JSON.stringify(value)): Writable { + const stored = localStorage.getItem(name) as T + let value = initial; + if (stored) { + value = modifier(stored) + } + + const writableStore = writable(value) + + writableStore.subscribe((value) => { + const reversed = reverseModifier(value); + localStorage.setItem(name, reversed) + }) + + return writableStore +} \ No newline at end of file diff --git a/src/client/lib/nachweisSpeichern.ts b/src/client/lib/nachweisSpeichern.ts new file mode 100644 index 00000000..6ec1ccd7 --- /dev/null +++ b/src/client/lib/nachweisSpeichern.ts @@ -0,0 +1,135 @@ + +import { api } from "astro-typesafe-api/client" +import { exclude } from "#lib/exclude.js"; +import Cookies from "js-cookie"; +import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js"; +import { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, UnterlageClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js"; +import { Enums } from "@ibcornelsen/database/client"; + +export async function nachweisSpeichern( + nachweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | BedarfsausweisWohnenClient, + objekt: ObjektClient, + aufnahme: AufnahmeClient, + bilder: BildClient[], + unterlagen: UnterlageClient[], + ausweisart: Enums.Ausweisart +) { + if (objekt.uid) { + await api.objekt._uid.PATCH.fetch({ + ...exclude(objekt, ["uid"]) + }, { + params: { + uid: objekt.uid + }, + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) +} else { + const { uid } = await api.objekt.PUT.fetch({ + ...exclude(objekt, ["uid"]) + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + + objekt.uid = uid; + } + + + + if (aufnahme.uid) { + await api.aufnahme._uid.PATCH.fetch({ + ...exclude(aufnahme, ["uid"]), + baujahr_gebaeude: aufnahme.baujahr_gebaeude || [], + baujahr_klima: aufnahme.baujahr_klima || [], + baujahr_heizung: aufnahme.baujahr_heizung || [], + }, { + params: { + uid: aufnahme.uid + }, + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + } else { + const { uid } = await api.aufnahme.PUT.fetch({ + aufnahme, + uid_objekt: objekt.uid + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + + aufnahme.uid = uid + } + + let patchRoute: any; + let putRoute: any; + if (ausweisart == Enums.Ausweisart.GEGNachweisWohnen) { + patchRoute = api["geg-nachweis-wohnen"]._uid.PATCH + putRoute = api["geg-nachweis-wohnen"].PUT + } + + if (nachweis.uid) { + await patchRoute.fetch({ + ...exclude(nachweis, ["uid"]) + }, { + params: { + uid: nachweis.uid + }, + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + } else { + const { uid } = await putRoute.fetch({ + nachweis, + uid_aufnahme: aufnahme.uid + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + + nachweis.uid = uid; + } + + await api.aufnahme._uid.bilder.PUT.fetch(bilder.map(bild => bild.uid), { + params: { + uid: aufnahme.uid + }, + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + + return { + uid_nachweis: nachweis.uid, + uid_aufnahme: aufnahme.uid, + uid_objekt: objekt.uid + } + + + // await client.v1.tickets.erstellen.mutate({ + // titel: "Ausweis konnte nicht gespeichert werden", + // beschreibung: e.stack, + // email: user.email ?? "", + // metadata: JSON.stringify({ + // ausweis, + // }), + // }); + + // addNotification({ + // dismissable: false, + // message: + // "Ausweis konnte nicht gespeichert werden, bitte versuchen sie es erneut.", + // subtext: + // "Sollte das Problem weiterhin bestehen, kontaktieren sie bitte den Support.", + // timeout: 6000, + // type: "error", + // }); + return null; +} diff --git a/src/components/Ausweis/Ausweisart.svelte b/src/components/Ausweis/Ausweisart.svelte index 551783fe..27721e77 100644 --- a/src/components/Ausweis/Ausweisart.svelte +++ b/src/components/Ausweis/Ausweisart.svelte @@ -48,7 +48,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 required data-cy="ausstellgrund" > - + {#each Object.entries(Enums.Ausstellgrund) as [name, ausstellgrund]} {/each} diff --git a/src/components/Ausweis/ButtonWeiterHilfe.svelte b/src/components/Ausweis/ButtonWeiterHilfe.svelte index 94777702..d55af6eb 100644 --- a/src/components/Ausweis/ButtonWeiterHilfe.svelte +++ b/src/components/Ausweis/ButtonWeiterHilfe.svelte @@ -1,16 +1,18 @@