diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index fd3dc1a0..ec71ff20 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -5,6 +5,7 @@ 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"), @@ -12,13 +13,12 @@ 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"), "admin/stornieren": await import("../src/pages/api/admin/stornieren.ts"), - "bedarfsausweis-gewerbe/[uid]": await import("../src/pages/api/bedarfsausweis-gewerbe/[uid].ts"), - "bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"), + "ausweise": await import("../src/pages/api/ausweise/index.ts"), "auth/access-token": await import("../src/pages/api/auth/access-token.ts"), "auth/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.ts"), "auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"), - "ausweise": await import("../src/pages/api/ausweise/index.ts"), - "aufnahme": await import("../src/pages/api/aufnahme/index.ts"), + "bedarfsausweis-gewerbe/[uid]": await import("../src/pages/api/bedarfsausweis-gewerbe/[uid].ts"), + "bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"), "bedarfsausweis-wohnen/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].ts"), "bedarfsausweis-wohnen": await import("../src/pages/api/bedarfsausweis-wohnen/index.ts"), "bilder/[id]": await import("../src/pages/api/bilder/[id].ts"), diff --git a/src/client/lib/ausweisSpeichern.ts b/src/client/lib/ausweisSpeichern.ts index db460ed6..741381ee 100644 --- a/src/client/lib/ausweisSpeichern.ts +++ b/src/client/lib/ausweisSpeichern.ts @@ -3,7 +3,7 @@ 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, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js"; +import { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js"; import { Enums } from "#lib/client/prisma.js"; export async function ausweisSpeichern( diff --git a/src/client/lib/bilderHochladen.ts b/src/client/lib/bilderHochladen.ts deleted file mode 100644 index 11aa2176..00000000 --- a/src/client/lib/bilderHochladen.ts +++ /dev/null @@ -1,95 +0,0 @@ -import { - ObjektClient, - UploadedGebaeudeBild, - VerbrauchsausweisWohnenClient, -} from "#components/Ausweis/types.js"; -import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js"; -import { Enums } from "#lib/client/prisma"; -import { addNotification, updateNotification } from "@ibcornelsen/ui"; -import { api } from "astro-typesafe-api/client"; -import Cookies from "js-cookie"; - -export async function bilderHochladen( - images: (UploadedGebaeudeBild & { base64?: string, update?: boolean })[], - aufnahme_uid: string -) { - if (images.length == 0) { - return images; - } - - // Wenn Bilder hochgeladen werden konvertieren wir sie zu base64, das heißt, dass die base64 Eigenschaft bei diesen Bildern - // existiert. Das müssen wir TypeScript nur wissen lassen, damit es uns in Ruhe lässt. - const imagesToUpload = images.filter( - (image) => !image.uid || image.update - ) as unknown as { - data: string; - kategorie: string; - uid?: string; - update: boolean; - }[]; - - if (imagesToUpload.length == 0) { - return images; - } - - // Alle Bilder hochladen - const notification = addNotification({ - dismissable: false, - message: "Bilder hochladen.", - subtext: `${imagesToUpload.length} Bilder werden hochgeladen, bitte haben sie Geduld.`, - timeout: 0, - type: "info", - }); - for (let i = 0; i < imagesToUpload.length; i++) { - const image = imagesToUpload[i]; - - try { - if (image.update) { - await api.bilder._uid.PATCH.fetch({ - data: image.data, - kategorie: image.kategorie as Enums.BilderKategorie, - }, { - params: { - uid: image.uid as string, - }, - headers: { - "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` - } - }); - } else { - const response = await api.aufnahme._uid.bilder.PUT.fetch({ - data: image.data, - kategorie: image.kategorie as Enums.BilderKategorie - }, { - params: { - uid: aufnahme_uid - }, - headers: { - "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` - } - }); - - image.uid = response.uid; - } - - updateNotification(notification, { - dismissable: true, - message: "Bild hochgeladen.", - subtext: `${i + 1}/${ - imagesToUpload.length - } Bildern wurden erfolgreich hochgeladen.`, - timeout: 3000, - }); - } catch (e) { - updateNotification(notification, { - dismissable: true, - message: "Bild konnte nicht hochgeladen werden.", - subtext: `Eines ihrer Bilder konnte nicht hochgeladen werden. Wir haben bereits ein Ticket erstellt und melden uns so schnell wie möglich bei ihnen.`, - timeout: 15000, - type: "error", - }); - } - } - - return images; -} diff --git a/src/client/lib/nachweisSpeichern.ts b/src/client/lib/nachweisSpeichern.ts index d0ec3ca0..2bd84c6d 100644 --- a/src/client/lib/nachweisSpeichern.ts +++ b/src/client/lib/nachweisSpeichern.ts @@ -3,7 +3,7 @@ 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 { AufnahmeClient, BedarfsausweisWohnenClient, BildClient, ObjektClient, UnterlageClient, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient, } from "#components/Ausweis/types.js"; import { Enums } from "#lib/client/prisma.js"; export async function nachweisSpeichern( @@ -14,8 +14,8 @@ export async function nachweisSpeichern( unterlagen: UnterlageClient[], ausweisart: Enums.Ausweisart ) { - if (objekt.uid) { - await api.objekt._uid.PATCH.fetch({ + if (objekt.id) { + await api.objekt._id.PATCH.fetch({ adresse: objekt.adresse, latitude: 0, longitude: 0, @@ -23,14 +23,14 @@ export async function nachweisSpeichern( plz: objekt.plz }, { params: { - uid: objekt.uid + id: objekt.id }, headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` } }) } else { - const { uid } = await api.objekt.PUT.fetch({ + const { id } = await api.objekt.PUT.fetch({ adresse: objekt.adresse, latitude: 0, longitude: 0, @@ -42,13 +42,13 @@ export async function nachweisSpeichern( } }) - objekt.uid = uid; + objekt.id = id; } - if (aufnahme.uid) { - await api.aufnahme._uid.PATCH.fetch({ + if (aufnahme.id) { + await api.aufnahme._id.PATCH.fetch({ baujahr_gebaeude: aufnahme.baujahr_gebaeude || [], baujahr_heizung: aufnahme.baujahr_heizung || [], baujahr_klima: aufnahme.baujahr_klima || [], @@ -103,14 +103,14 @@ export async function nachweisSpeichern( zirkulation: aufnahme.zirkulation }, { params: { - uid: aufnahme.uid + id: aufnahme.id }, headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` } }) } else { - const { uid } = await api.aufnahme.PUT.fetch({ + const { id } = await api.aufnahme.PUT.fetch({ aufnahme: { baujahr_gebaeude: aufnahme.baujahr_gebaeude, baujahr_heizung: aufnahme.baujahr_heizung, @@ -166,56 +166,56 @@ export async function nachweisSpeichern( zentralheizung: aufnahme.zentralheizung, zirkulation: aufnahme.zirkulation }, - uid_objekt: objekt.uid + objekt_id: objekt.id }, { headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` } }) - aufnahme.uid = uid + aufnahme.id = id } let patchRoute: any; let putRoute: any; if (ausweisart == Enums.Ausweisart.GEGNachweisWohnen) { - patchRoute = api["geg-nachweis-wohnen"]._uid.PATCH + patchRoute = api["geg-nachweis-wohnen"]._id.PATCH putRoute = api["geg-nachweis-wohnen"].PUT } else if (ausweisart === Enums.Ausweisart.GEGNachweisGewerbe) { - patchRoute = api["geg-nachweis-gewerbe"]._uid.PATCH + patchRoute = api["geg-nachweis-gewerbe"]._id.PATCH putRoute = api["geg-nachweis-gewerbe"].PUT } else if (ausweisart === Enums.Ausweisart.BedarfsausweisGewerbe) { - patchRoute = api["bedarfsausweis-gewerbe"]._uid.PATCH + patchRoute = api["bedarfsausweis-gewerbe"]._id.PATCH putRoute = api["bedarfsausweis-gewerbe"].PUT } - if (nachweis.uid) { + if (nachweis.id) { await patchRoute.fetch({ - ...exclude(nachweis, ["uid"]) + ...exclude(nachweis, ["id"]) }, { params: { - uid: nachweis.uid + id: nachweis.id }, headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` } }) } else { - const { uid } = await putRoute.fetch({ + const { id } = await putRoute.fetch({ nachweis, - uid_aufnahme: aufnahme.uid + uid_aufnahme: aufnahme.id }, { headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` } }) - nachweis.uid = uid; + nachweis.id = id; } - await api.aufnahme._uid.bilder.PUT.fetch(bilder.map(bild => bild.uid), { + await api.aufnahme._id.bilder.PUT.fetch(bilder.map(bild => bild.id), { params: { - uid: aufnahme.uid + id: aufnahme.id }, headers: { "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` @@ -223,8 +223,8 @@ export async function nachweisSpeichern( }) return { - uid_nachweis: nachweis.uid, - uid_aufnahme: aufnahme.uid, - uid_objekt: objekt.uid + nachweis_id: nachweis.id, + aufnahme_id: aufnahme.id, + objekt_id: objekt.id } } diff --git a/src/components/AnsichtsausweisButton.svelte b/src/components/AnsichtsausweisButton.svelte index 10167b6b..3990611b 100644 --- a/src/components/AnsichtsausweisButton.svelte +++ b/src/components/AnsichtsausweisButton.svelte @@ -1,13 +1,12 @@ diff --git a/src/components/Ausweis/AnlagenTechnik.svelte b/src/components/Ausweis/AnlagenTechnik.svelte index 757f9cc2..a3077d1b 100644 --- a/src/components/Ausweis/AnlagenTechnik.svelte +++ b/src/components/Ausweis/AnlagenTechnik.svelte @@ -2,7 +2,7 @@ import { AufnahmeClient, ObjektClient, - UploadedGebaeudeBild, + BildClient, } from "./types.js"; import SanierungsOption from "#components/Ausweis/SanierungsOption.svelte"; import AnlagenTechnikImage from "./AnlagenTechnikImage.svelte"; @@ -11,7 +11,7 @@ export let objekt: ObjektClient; export let aufnahme: AufnahmeClient; export let ausweis: BedarfsausweisGewerbe; - export let images: UploadedGebaeudeBild[]; + export let images: BildClient[];
+


{ausweis.uid}{ausweis.id}
+
{:else}
{/if}
@@ -29,14 +29,14 @@
diff --git a/src/components/DatenblattButton.svelte b/src/components/DatenblattButton.svelte
index b2164453..4fc22fe4 100644
--- a/src/components/DatenblattButton.svelte
+++ b/src/components/DatenblattButton.svelte
@@ -1,13 +1,13 @@