diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index 78e89147..c2ff6be3 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -5,30 +5,31 @@ 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"), + "ausweise": await import("../src/pages/api/ausweise/index.ts"), + "bedarfsausweis-gewerbe/[id]": await import("../src/pages/api/bedarfsausweis-gewerbe/[id].ts"), + "bedarfsausweis-gewerbe": await import("../src/pages/api/bedarfsausweis-gewerbe/index.ts"), "admin/ausstellen": await import("../src/pages/api/admin/ausstellen.ts"), + "admin/bedarfsausweis-ausstellen": await import("../src/pages/api/admin/bedarfsausweis-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/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/[id]": await import("../src/pages/api/bedarfsausweis-wohnen/[id].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/passwort-vergessen": await import("../src/pages/api/auth/passwort-vergessen.ts"), "auth/refresh-token": await import("../src/pages/api/auth/refresh-token.ts"), - "bedarfsausweis-gewerbe/[id]": await import("../src/pages/api/bedarfsausweis-gewerbe/[id].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"), "geg-nachweis-gewerbe/[id]": await import("../src/pages/api/geg-nachweis-gewerbe/[id].ts"), "geg-nachweis-gewerbe": await import("../src/pages/api/geg-nachweis-gewerbe/index.ts"), "geg-nachweis-wohnen/[id]": await import("../src/pages/api/geg-nachweis-wohnen/[id].ts"), "geg-nachweis-wohnen": await import("../src/pages/api/geg-nachweis-wohnen/index.ts"), - "objekt": await import("../src/pages/api/objekt/index.ts"), "rechnung/[id]": await import("../src/pages/api/rechnung/[id].ts"), "rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"), "rechnung": await import("../src/pages/api/rechnung/index.ts"), + "objekt": await import("../src/pages/api/objekt/index.ts"), "ticket": await import("../src/pages/api/ticket/index.ts"), "user": await import("../src/pages/api/user/index.ts"), "user/self": await import("../src/pages/api/user/self.ts"), diff --git a/src/components/Dashboard/DashboardAusweis.svelte b/src/components/Dashboard/DashboardAusweis.svelte index 75728b52..bf36b78a 100644 --- a/src/components/Dashboard/DashboardAusweis.svelte +++ b/src/components/Dashboard/DashboardAusweis.svelte @@ -5,7 +5,6 @@ import { CrossCircled, DotsVertical, - Download, Pencil2, QuestionMarkCircled, } from "radix-svelte-icons"; @@ -28,10 +27,8 @@ import DashboardNotification from "./DashboardNotification.svelte"; import { notifications } from "#components/NotificationProvider/shared.js"; import { Bell } from "radix-svelte-icons"; - import { A13BerechnungRechnerischeLaufzeitHeizung } from "#lib/Berechnungen/BedarfsausweisWohnen/A13BerechnungRechnerischeLaufzeitHeizung.js"; - import mime from "mime" - import { getGEGNachweisGewerbe } from "#lib/server/db.js"; - + import mime from "mime" + const progress = ausweis.ausgestellt ? 100 : ausweis.bestellt ? 66 : 33; const ausweisart = getAusweisartFromId(ausweis.id); @@ -151,6 +148,8 @@ } } + + async function ausstellen(post = false) { const notification = addNotification({ message: "Ausweis wird ausgestellt.", @@ -158,33 +157,124 @@ type: "info", timeout: 0, }) - try { - await api.admin.ausstellen.GET.fetch({ - id_ausweis: ausweis.id, - post - }, { - headers: { - "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + + if (ausweisart === Enums.Ausweisart.BedarfsausweisWohnen) { + const results: {data: string, name: string, type: "Sonstiges" | "Ausweis"}[] = [] + for (const file of bedarfsausweisAdditionalInput.files || []) { + const reader = new FileReader(); + + reader.onload = (ev) => { + const result = reader.result; + + if (!result) { + addNotification({ + message: `Die Datei ${file.name} konnte nicht verarbeitet werden.`, + timeout: 3000, + type: "error", + dismissable: true + }) + } + + results.push({ + data: result as string, + name: file.name, + type: "Sonstiges" + }) } - }) + reader.readAsDataURL(file) + } - ausweis.ausgestellt = true; + // Jetzt holen wir uns noch den Ausweis + const files = bedarfsausweisFileInput.files + const reader = new FileReader() - updateNotification(notification, { - message: "Ausweis ausgestellt.", - subtext: "Der Ausweis wurde erfolgreich ausgestellt.", - timeout: 3000, - type: "success", - }) - } catch(e) { - updateNotification(notification, { - message: "Das hat nicht geklappt.", - subtext: e as string, - timeout: 3000, - type: "error", - }) + if (files === null || (files.length === 0)) { + addNotification({ + message: "Bitte laden sie vor dem Ausstellen einen Ausweis hoch.", + timeout: 3000, + type: "error", + dismissable: true + }) + return; + } + + reader.onload = (ev) => { + const result = reader.result; + + if (!result) { + addNotification({ + message: `Die Datei ${files[0].name} konnte nicht verarbeitet werden.`, + timeout: 3000, + type: "error", + dismissable: true + }) + } + + results.push({ + data: result as string, + name: files[0].name, + type: "Ausweis" + }) + } + + reader.readAsDataURL(files[0]) + + try { + await api.admin["bedarfsausweis-ausstellen"].POST.fetch({ + id_ausweis: ausweis.id, + post, + files: results + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + updateNotification(notification, { + message: "Ausweis ausgestellt.", + subtext: "Der Ausweis wurde erfolgreich ausgestellt.", + timeout: 3000, + type: "success", + }) + } catch(e) { + updateNotification(notification, { + message: "Das hat nicht geklappt.", + subtext: e as string, + timeout: 3000, + type: "error", + }) + } + } else { + try { + await api.admin.ausstellen.GET.fetch({ + id_ausweis: ausweis.id, + post + }, { + headers: { + "Authorization": `Bearer ${Cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)}` + } + }) + + ausweis.ausgestellt = true; + + updateNotification(notification, { + message: "Ausweis ausgestellt.", + subtext: "Der Ausweis wurde erfolgreich ausgestellt.", + timeout: 3000, + type: "success", + }) + } catch(e) { + updateNotification(notification, { + message: "Das hat nicht geklappt.", + subtext: e as string, + timeout: 3000, + type: "error", + }) + } } } + + let bedarfsausweisFileInput: HTMLInputElement; + let bedarfsausweisAdditionalInput: HTMLInputElement;