diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index e1230ee3..32f79f5b 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -5,23 +5,25 @@ export const createCaller = createCallerFactory({ "klimafaktoren": await import("../src/pages/api/klimafaktoren.ts"), "postleitzahlen": await import("../src/pages/api/postleitzahlen.ts"), "unterlage": await import("../src/pages/api/unterlage.ts"), - "aufnahme": await import("../src/pages/api/aufnahme/index.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"), "admin/nicht-ausstellen": await import("../src/pages/api/admin/nicht-ausstellen.ts"), "admin/post-ausstellen": await import("../src/pages/api/admin/post-ausstellen.ts"), "admin/registriernummer": await import("../src/pages/api/admin/registriernummer.ts"), + "admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"), + "aufnahme": await import("../src/pages/api/aufnahme/index.ts"), + "ausweise": await import("../src/pages/api/ausweise/index.ts"), + "bedarfsausweis-wohnen/[uid]": await import("../src/pages/api/bedarfsausweis-wohnen/[uid].ts"), + "bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/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"), - "geg-nachweis-gewerbe/[uid]": await import("../src/pages/api/geg-nachweis-gewerbe/[uid].ts"), - "geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"), "geg-nachweis-wohnen/[uid]": await import("../src/pages/api/geg-nachweis-wohnen/[uid].ts"), "geg-nachweis-wohnen": await import("../src/pages/api/geg-nachweis-wohnen/index.ts"), + "geg-nachweis-gewerbe/[uid]": await import("../src/pages/api/geg-nachweis-gewerbe/[uid].ts"), + "geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"), "objekt": await import("../src/pages/api/objekt/index.ts"), "rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"), "rechnung": await import("../src/pages/api/rechnung/index.ts"), diff --git a/src/client/lib/helpers.ts b/src/client/lib/helpers.ts index 5e1e0c0a..aef33eaf 100644 --- a/src/client/lib/helpers.ts +++ b/src/client/lib/helpers.ts @@ -1,4 +1,5 @@ import { writable, Writable } from "svelte/store"; +import { ZodEffects, ZodNullable, ZodOptional, ZodType } from "zod"; 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 @@ -15,4 +16,30 @@ export function localStorageSync(initial: T, name: string, modifier: (stored: }) return writableStore +} + +export function isZodInstanceOf>( + schema: ZodType, + targetType: new (...args: any) => T +): schema is T { + if (schema instanceof targetType) { + return true; + } + + if (schema instanceof ZodOptional || schema instanceof ZodNullable) { + return isZodInstanceOf(schema._def.innerType, targetType); + }else if (schema instanceof ZodEffects) { + return getZodBaseType(schema._def.schema) + } + + return false; +} + +export function getZodBaseType(schema: ZodType): ZodType { + if (schema instanceof ZodOptional || schema instanceof ZodNullable) { + return getZodBaseType(schema._def.innerType); + } else if (schema instanceof ZodEffects) { + return getZodBaseType(schema._def.schema) + } + return schema; } \ No newline at end of file diff --git a/src/components/Ausweis/Ausweisart.svelte b/src/components/Ausweis/Ausweisart.svelte index 27721e77..06184aad 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} @@ -72,7 +72,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 required bind:value={aufnahme.gebaeudetyp} > - + {#if ausweisart==Enums.Ausweisart.VerbrauchsausweisWohnen || ausweisart === Enums.Ausweisart.GEGNachweisWohnen} @@ -224,7 +224,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 required bind:value={aufnahme.saniert} > - + diff --git a/src/components/Ausweis/GebaeudeDaten.svelte b/src/components/Ausweis/GebaeudeDaten.svelte index b0768d10..f0c1db2a 100644 --- a/src/components/Ausweis/GebaeudeDaten.svelte +++ b/src/components/Ausweis/GebaeudeDaten.svelte @@ -121,7 +121,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 bind:value={aufnahme.dachgeschoss} required > - + diff --git a/src/components/Ausweis/LueftungundLeerstand.svelte b/src/components/Ausweis/LueftungundLeerstand.svelte index 222f9c3c..13259756 100644 --- a/src/components/Ausweis/LueftungundLeerstand.svelte +++ b/src/components/Ausweis/LueftungundLeerstand.svelte @@ -29,7 +29,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 bind:value={aufnahme.gebaeudeteil} required > - + @@ -79,7 +79,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 required bind:value={aufnahme.lueftung} > - + + diff --git a/src/components/Ausweis/StromVerbrauch.svelte b/src/components/Ausweis/StromVerbrauch.svelte index 72320030..6607459d 100644 --- a/src/components/Ausweis/StromVerbrauch.svelte +++ b/src/components/Ausweis/StromVerbrauch.svelte @@ -223,7 +223,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 bind:value={aufnahme.brennstoff_1} required > - + {#each Object.keys(fuelMap) as fuel} {/each} diff --git a/src/components/Ausweis/types.ts b/src/components/Ausweis/types.ts index df418a6a..a7efdc16 100644 --- a/src/components/Ausweis/types.ts +++ b/src/components/Ausweis/types.ts @@ -165,9 +165,10 @@ export type ObjektKomplettClient = ObjektClient & { export type AufnahmeKomplettClient = AufnahmeClient & { bilder: BildClient[], unterlagen: UnterlageClient[], - bedarfsausweis_wohnen?: BedarfsausweisWohnenClient, - verbrauchsausweis_wohnen?: VerbrauchsausweisWohnenClient, - verbrauchsausweis_gewerbe?: VerbrauchsausweisGewerbeClient + bedarfsausweise_wohnen: BedarfsausweisWohnenClient[], + verbrauchsausweise_wohnen: VerbrauchsausweisWohnenClient[], + verbrauchsausweise_gewerbe: VerbrauchsausweisGewerbeClient[], + geg_nachweise_wohnen: GEGNachweisWohnenClient[] } export type GEGNachweisWohnenClient = Omit & { diff --git a/src/components/AusweisPruefenBox.svelte b/src/components/AusweisPruefenBox.svelte index 92580386..ccedb598 100644 --- a/src/components/AusweisPruefenBox.svelte +++ b/src/components/AusweisPruefenBox.svelte @@ -9,7 +9,7 @@ VerbrauchsausweisWohnenClient, } from "./Ausweis/types.js"; import AusweisPruefenTooltip from "./AusweisPruefenTooltip.svelte"; - import { addNotification } from "./NotificationProvider/shared.js"; + import { addNotification } from "#components/Notifications/shared.js"; import { CheckCircled, CrossCircled, Image } from "radix-svelte-icons"; import ChevronDown from "radix-svelte-icons/src/lib/icons/ChevronDown.svelte"; import { Event } from "@ibcornelsen/database/client"; @@ -31,16 +31,16 @@ async function ausweisAusstellen(uid: string) { try { await api.admin.ausstellen.GET.fetch({ - uid - }, { - headers: { - "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` - } - }) + uid_ausweis: uid + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) } catch(e) { addNotification({ - title: "Das hat nicht geklappt.", - description: e.cause.statusText, + message: "Das hat nicht geklappt.", + subtext: e as string, timeout: 3000, type: "error", }) @@ -49,7 +49,7 @@ - const ausweisArt = getAusweisartFromUUID(ausweis.uid) // TODO: Das ist ein Platzhalter, hier muss die Ausweisart aus dem Ausweisobjekt kommen + const ausweisArt = getAusweisartFromUUID(ausweis.uid) let verbrauchWWGesamt_1 = ""; let verbrauchWWGesamt_2 = ""; @@ -124,12 +124,12 @@ let Abgeschlossen: any; - if (aufnahme.erledigt) { + if (ausweis.ausgestellt) { Ausweisbild = "/images/dashboard/ausweishaken.jpg"; DatenBlattBild = "/images/dashboard/datenblatthaken.jpg"; StatusIcon = "/images/dashboard/erledigt.svg"; Abgeschlossen = 0; - } else if (aufnahme.bestellt) { + } else if (ausweis.bestellt) { Ausweisbild = "/images/dashboard/ausweis.jpg"; DatenBlattBild = "/images/dashboard/datenblatt.jpg"; StatusIcon = "/images/dashboard/bestellt.svg"; @@ -147,7 +147,7 @@ symbolPruefung = "/images/dashboard/kreiskreuz.png"; } - if (aufnahme.zurueckgestellt) { + if (ausweis.zurueckgestellt) { zurueckGestellt = "Status"; } else { @@ -456,16 +456,33 @@ // } async function stornieren(ausweis: VerbrauchsausweisWohnenClient) { - addNotification({ - title: "Ausweis wurde storniert", - type: "success", - dismissable: true, - timeout: 3000, - }) + try { + const response = await api.admin.stornieren.PUT.fetch({ + uid_ausweis: ausweis.uid + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) - ausweis.aufnahme.storniert = true; + addNotification({ + message: "Ausweis wurde storniert", + type: "success", + dismissable: true, + timeout: 3000, + }) - ausweis = ausweis; + ausweis.storniert = true; + ausweis = ausweis; + } catch(e) { + addNotification({ + message: "Ausweis konnte nicht storniert werden.", + subtext: e as string, + type: "error", + dismissable: true, + timeout: 3000, + }) + } } let bilderModal: HTMLDialogElement; @@ -473,13 +490,23 @@ async function registriernummerAnfordern(uid: string) { - const result = await api.admin.registriernummer.GET.fetch({ - uid - }, { - headers: { - "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` - } - }) + try { + const result = await api.admin.registriernummer.GET.fetch({ + uid + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + } catch(e) { + addNotification({ + message: "Registriernummer anfordern fehlgeschlagen.", + subtext: e as string, + type: "error", + dismissable: true, + timeout: 3000, + }) + } } @@ -909,4 +936,4 @@ - \ No newline at end of file + \ No newline at end of file diff --git a/src/components/Dashboard/AusweisePruefenFilter.svelte b/src/components/Dashboard/AusweisePruefenFilter.svelte new file mode 100644 index 00000000..d0636203 --- /dev/null +++ b/src/components/Dashboard/AusweisePruefenFilter.svelte @@ -0,0 +1,68 @@ + + +{#each filters as filter, i} + {@const type = getZodBaseType(filter.type)} +
+ {#if i === 0} + where + {:else} + and + {/if} + + equals + {#if type instanceof ZodNumber} + + {:else if type instanceof ZodBoolean} + + {:else if type instanceof ZodNativeEnum} + + {:else} + + {/if} + +
+{/each} + + + + + \ No newline at end of file diff --git a/src/components/Dashboard/DashboardAusweis.svelte b/src/components/Dashboard/DashboardAusweis.svelte index bf034c34..dc2b81cc 100644 --- a/src/components/Dashboard/DashboardAusweis.svelte +++ b/src/components/Dashboard/DashboardAusweis.svelte @@ -13,11 +13,11 @@ import { api } from "astro-typesafe-api/client"; import Cookies from "js-cookie"; import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js"; - import { Enums } from "@ibcornelsen/database/client"; + import { Enums, Objekt } from "@ibcornelsen/database/client"; export let ausweis: VerbrauchsausweisWohnenClient; export let aufnahme: AufnahmeKomplettClient; - export let objekt: ObjektKomplettClient; + export let objekt: Objekt; export let progress: number; const ausweisart = getAusweisartFromUUID(ausweis.uid); @@ -188,14 +188,14 @@ {/await} -
+
Bearbeiten +
diff --git a/src/components/Dashboard/DashboardObjekt.svelte b/src/components/Dashboard/DashboardObjekt.svelte index 9b1b6a35..a60ea685 100644 --- a/src/components/Dashboard/DashboardObjekt.svelte +++ b/src/components/Dashboard/DashboardObjekt.svelte @@ -2,12 +2,12 @@ import { ObjektKomplettClient } from "#components/Ausweis/types.js"; import { Enums } from "@ibcornelsen/database/server"; import moment from "moment"; - import { OpenInNewWindow } from "radix-svelte-icons"; + import { File, OpenInNewWindow } from "radix-svelte-icons"; export let objekt: ObjektKomplettClient; -
+
{#if objekt.aufnahmen.length > 0} {@const bild = objekt.aufnahmen[0].bilder.find(bild => bild.kategorie === Enums.BilderKategorie.Gebaeude)} @@ -17,13 +17,28 @@ {/if}
-
-

{objekt.adresse}

+
+

{objekt.adresse}, {objekt.plz} {objekt.ort}

{moment(objekt.erstellungsdatum).format("DD.MM.YYYY")}
-
- +
+ {#each objekt.aufnahmen as aufnahme} +
+
+ Sanierungsstand vom {moment(aufnahme.erstellungsdatum).format("DD.MM.YYYY")} + +
+
+ {#if aufnahme.verbrauchsausweise_wohnen} + + {/if} + {#if aufnahme.verbrauchsausweis_gewerbe} + + {/if} +
+
+ {/each}
\ No newline at end of file diff --git a/src/components/Dashboard/DashboardSidebar.svelte b/src/components/Dashboard/DashboardSidebar.svelte index 88a84742..9dc3b2dc 100644 --- a/src/components/Dashboard/DashboardSidebar.svelte +++ b/src/components/Dashboard/DashboardSidebar.svelte @@ -46,16 +46,12 @@ /> -