From 80b88df992b30a615171c018199219eb361e09b2 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Sun, 23 Feb 2025 22:58:17 +1100 Subject: [PATCH] Kleinere Fehler gefixt --- Makefile | 4 +- .../20250223113449_migration/migration.sql | 47 ++++++++++++ src/astro-typesafe-api-caller.ts | 10 +-- .../Ausweis/Rechnungsadresse.svelte | 2 +- .../widgets/WelcherAusweisWidget_IBC.svelte | 2 +- src/lib/pdf/elements/Image.ts | 4 + .../pdfDatenblattVerbrauchsausweisWohnen.ts | 73 +------------------ src/lib/pdf/pdfVerbrauchsausweisWohnen.ts | 22 +++--- src/modules/KundendatenModule.svelte | 26 +++++-- src/pages/pdf/datenblatt.ts | 2 +- 10 files changed, 93 insertions(+), 99 deletions(-) create mode 100644 prisma/migrations/20250223113449_migration/migration.sql diff --git a/Makefile b/Makefile index 13e78cab..d07b36d4 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ BACKUP_FILENAME := $(HOME)/backups/$(shell date +"%Y-%m-%d_%H-%M-%S").sql.gz online-energieausweis: bun run dev --host -dev: install-dependencies database online-energieausweis +dev: database online-energieausweis database: docker compose up @@ -69,4 +69,4 @@ prod: install-dependencies run-database # - echo "CERTIFICATE=$(cat /etc/letsencrypt/live/ibcornelsen.de/fullchain.pem | base64 | tr -d '\n')" >> ~/online-energieausweis/.env; - pm2 delete online-energieausweis - pm2 start --name "online-energieausweis" --log ~/logs/`date '+%d-%m-%Y_%H:%M:%S'`.log --time bun -- run ./server.ts \ No newline at end of file + NODE_ENV="production" pm2 start --name "online-energieausweis" --update-env --log ~/logs/`date '+%d-%m-%Y_%H:%M:%S'`.log --time bun -- run ./server.ts \ No newline at end of file diff --git a/prisma/migrations/20250223113449_migration/migration.sql b/prisma/migrations/20250223113449_migration/migration.sql new file mode 100644 index 00000000..4e4efaa6 --- /dev/null +++ b/prisma/migrations/20250223113449_migration/migration.sql @@ -0,0 +1,47 @@ +-- AlterTable +ALTER TABLE "Anteilshaber" ALTER COLUMN "uid" SET DEFAULT 'ant-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Aufnahme" ALTER COLUMN "uid" SET DEFAULT 'auf-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "BedarfsausweisGewerbe" ALTER COLUMN "uid" SET DEFAULT 'bag-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "BedarfsausweisWohnen" ALTER COLUMN "uid" SET DEFAULT 'baw-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Bild" ALTER COLUMN "uid" SET DEFAULT 'img-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Event" ALTER COLUMN "uid" SET DEFAULT 'evt-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "GEGEinpreisung" ALTER COLUMN "uid" SET DEFAULT 'gge-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "GEGNachweisGewerbe" ALTER COLUMN "uid" SET DEFAULT 'gnw-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "GEGNachweisWohnen" ALTER COLUMN "uid" SET DEFAULT 'gnw-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Objekt" ALTER COLUMN "uid" SET DEFAULT 'obj-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Rechnung" ALTER COLUMN "uid" SET DEFAULT 'inv-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Tickets" ALTER COLUMN "uid" SET DEFAULT 'tkt-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "Unterlage" ALTER COLUMN "uid" SET DEFAULT 'pln-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "VerbrauchsausweisGewerbe" ALTER COLUMN "uid" SET DEFAULT 'vag-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "VerbrauchsausweisWohnen" ALTER COLUMN "uid" SET DEFAULT 'vaw-' || gen_random_uuid(); + +-- AlterTable +ALTER TABLE "benutzer" ALTER COLUMN "uid" SET DEFAULT 'usr-' || gen_random_uuid(); diff --git a/src/astro-typesafe-api-caller.ts b/src/astro-typesafe-api-caller.ts index ca019c6a..2ed48238 100644 --- a/src/astro-typesafe-api-caller.ts +++ b/src/astro-typesafe-api-caller.ts @@ -14,29 +14,27 @@ export const createCaller = createCallerFactory({ "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"), - "ausweise": await import("../src/pages/api/ausweise/index.ts"), - "aufnahme": await import("../src/pages/api/aufnahme/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"), "objekt": await import("../src/pages/api/objekt/index.ts"), - "ticket": await import("../src/pages/api/ticket/index.ts"), "rechnung/anfordern": await import("../src/pages/api/rechnung/anfordern.ts"), "rechnung": await import("../src/pages/api/rechnung/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"), - "webhooks/mollie": await import("../src/pages/api/webhooks/mollie.ts"), "verbrauchsausweis-gewerbe/[uid]": await import("../src/pages/api/verbrauchsausweis-gewerbe/[uid].ts"), "verbrauchsausweis-gewerbe": await import("../src/pages/api/verbrauchsausweis-gewerbe/index.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"), "aufnahme/[uid]/unterlagen": await import("../src/pages/api/aufnahme/[uid]/unterlagen.ts"), diff --git a/src/components/Ausweis/Rechnungsadresse.svelte b/src/components/Ausweis/Rechnungsadresse.svelte index 1f0b4868..1d689dd0 100644 --- a/src/components/Ausweis/Rechnungsadresse.svelte +++ b/src/components/Ausweis/Rechnungsadresse.svelte @@ -87,7 +87,7 @@ xl:grid-cols-3 xl:gap-x-8 xl:gap-y-8 name="rechnung_ort" type="text" required - value={rechnung.ort} + bind:value={rechnung.ort} />
diff --git a/src/components/widgets/WelcherAusweisWidget_IBC.svelte b/src/components/widgets/WelcherAusweisWidget_IBC.svelte index a79cf9c0..5acda5be 100644 --- a/src/components/widgets/WelcherAusweisWidget_IBC.svelte +++ b/src/components/widgets/WelcherAusweisWidget_IBC.svelte @@ -2,7 +2,7 @@ import { fade } from "svelte/transition"; import WidgetCardTemplate from "#components/widgets/WidgetCardTemplate_IBC.svelte"; import { PRICES } from "#lib/constants.js"; - import { Enums } from "#lib/client/prisma"; + import { Enums } from "#lib/client/prisma.js"; let gebaeudetyp: string = "bitte auswählen"; let anlass: string = "bitte auswählen"; diff --git a/src/lib/pdf/elements/Image.ts b/src/lib/pdf/elements/Image.ts index c4a21cef..9e0ce5e3 100644 --- a/src/lib/pdf/elements/Image.ts +++ b/src/lib/pdf/elements/Image.ts @@ -43,6 +43,10 @@ export class Image extends PDFElement { async draw(page: PDFPage, x: number, y: number) { let embed: PDFImage; if (this.options.src) { + if (!fs.existsSync(this.options.src)) { + return; + } + const img = fs.readFileSync(this.options.src) if (this.options.src.split(".").pop() === "png") { embed = await page.doc.embedPng(img) diff --git a/src/lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.ts b/src/lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.ts index e64b478d..4e415c42 100644 --- a/src/lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.ts +++ b/src/lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.ts @@ -5,7 +5,7 @@ import { PDFDocument, rgb, StandardFonts, TextAlignment } from "pdf-lib"; import { checkbox, flex, text } from "./elements/index.js"; import { xml2pdf } from "./elements/xml2pdf.js"; import moment from "moment"; -import { BilderKategorie, Heizungsstatus } from "#lib/server/prisma"; +import { BilderKategorie, Heizungsstatus } from "#lib/server/prisma.js"; import { fileURLToPath } from "url"; import { copyPage } from "./utils/copyPage.js"; import { PERSISTENT_DIR } from "#lib/server/constants.js"; @@ -51,7 +51,7 @@ export async function pdfDatenblattVerbrauchsausweisWohnen(ausweis: Verbrauchsau } const innerWidth = pages[0].getWidth() - marginX * 2; - + const layout = xml2pdf(` ${benutzer.vorname} ${benutzer.name} ${benutzer.adresse} @@ -337,74 +337,5 @@ export async function pdfDatenblattVerbrauchsausweisWohnen(ausweis: Verbrauchsau layoutPage2.draw(pages[1], 0, pages[1].getHeight()) layoutPage3.draw(pages[2], 0, pages[2].getHeight()) - // const containerWidth = width - marginX; - - // const layout = flex([ - // flex([ - // checkbox(8, 8), text("Neubau", { - // color: rgb(0,0,0), - // font, - // fontSize: 12 - // }) - // ], { - // align: "center", - // justify: "center", - // gap: 5, - // height: 12, - // page: pages[0] - // }), - // flex([ - // checkbox(8, 8), text("Vermietung/Verkauf", { - // color: rgb(0,0,0), - // font, - // fontSize: 12 - // }) - // ], { - // align: "center", - // justify: "center", - // gap: 5, - // height: 12, - // page: pages[0] - // }), - // flex([ - // checkbox(8, 8), text("Modernisierung", { - // color: rgb(0,0,0), - // font, - // fontSize: 12 - // }) - // ], { - // align: "center", - // justify: "center", - // gap: 5, - // height: 12, - // page: pages[0] - // }), - // flex([ - // checkbox(8, 8), text("Sonstiges", { - // color: rgb(0,0,0), - // font, - // fontSize: 12 - // }) - // ], { - // align: "center", - // justify: "center", - // gap: 5, - // height: 12, - // page: pages[0] - // }) - // ], { - // align: "center", - // justify: "space-between", - // gap: 15, - // x: marginX, - // y: height - marginY - 165, - // height: 12, - // width: containerWidth - // }) - - // layout.draw(pages[0]) - - // pdf.getForm().flatten() - return pdf.save(); } \ No newline at end of file diff --git a/src/lib/pdf/pdfVerbrauchsausweisWohnen.ts b/src/lib/pdf/pdfVerbrauchsausweisWohnen.ts index d9ac0161..ef1faa84 100644 --- a/src/lib/pdf/pdfVerbrauchsausweisWohnen.ts +++ b/src/lib/pdf/pdfVerbrauchsausweisWohnen.ts @@ -86,15 +86,19 @@ export async function pdfVerbrauchsausweisWohnen(ausweis: VerbrauchsausweisWohne const bild = bilder && bilder.find(image => image.kategorie === Enums.BilderKategorie.Gebaeude); if (bild) { - const file = fs.readFileSync(fileURLToPath(new URL(`${PERSISTENT_DIR}/images/${bild.uid}.jpg`, import.meta.url))) - let image: PDFImage; - image = await pdf.embedJpg(file) - pages[0].drawImage(image, { - x: 460.5, - y: height - 289, - width: 111, - height: 138 - }) + const path = `${PERSISTENT_DIR}/images/${bild.uid}.jpg`; + + if (fs.existsSync(path)) { + const file = fs.readFileSync(fileURLToPath(new URL(path, import.meta.url))) + let image: PDFImage; + image = await pdf.embedJpg(file) + pages[0].drawImage(image, { + x: 460.5, + y: height - 289, + width: 111, + height: 138 + }) + } } // Nach 82 aus Wohnfläche ermittelt diff --git a/src/modules/KundendatenModule.svelte b/src/modules/KundendatenModule.svelte index 9aaa85f6..ebbb85c0 100644 --- a/src/modules/KundendatenModule.svelte +++ b/src/modules/KundendatenModule.svelte @@ -4,8 +4,8 @@ import Bereich from "#components/labels/Bereich.svelte"; import Ansprechpartner from "#components/Ausweis/Ansprechpartner.svelte"; import Rechnungsadresse from "#components/Ausweis/Rechnungsadresse.svelte"; - import type { Bezahlmethoden } from "#lib/client/prisma"; - import { Enums } from "#lib/client/prisma"; + import type { Bezahlmethoden } from "#lib/client/prisma.js"; + import { Enums } from "#lib/client/prisma.js"; import { dialogs } from "svelte-dialogs"; import LoginDialog from "#components/LoginDialog.svelte"; import { @@ -239,11 +239,19 @@ } if (result === null) { - addNotification({ - dismissable: true, - message: "Ups... Das hat nicht geklappt.", - subtext: "Der Ausweis konnte nicht gespeichert werden, bitte versuchen sie es erneut oder kontaktieren sie unseren Support." - }) + if (ausweisart === Enums.Ausweisart.GEGNachweisWohnen || ausweisart === Enums.Ausweisart.GEGNachweisGewerbe || ausweisart === Enums.Ausweisart.GEGNachweisBedarfsausweis) { + addNotification({ + dismissable: true, + message: "Ups... Das hat nicht geklappt.", + subtext: "Der Ausweis konnte nicht gespeichert werden, bitte versuchen sie es erneut oder kontaktieren sie unseren Support." + }) + } else { + addNotification({ + dismissable: true, + message: "Ups... Das hat nicht geklappt.", + subtext: "Ihre Anfrage für einen GEG Nachweis konnte nicht gespeichert werden, bitte versuchen sie es erneut oder kontaktieren sie unseren Support." + }) + } } try { @@ -350,9 +358,11 @@ {:else} - + {/if}
diff --git a/src/pages/pdf/datenblatt.ts b/src/pages/pdf/datenblatt.ts index 8c1a854b..e355325e 100644 --- a/src/pages/pdf/datenblatt.ts +++ b/src/pages/pdf/datenblatt.ts @@ -98,7 +98,7 @@ export const POST: APIRoute = async (Astro) => { const aufnahme = JSON.parse(params.get("aufnahme") || "{}"); const objekt = JSON.parse(params.get("objekt") || "{}"); const bilder = JSON.parse(params.get("bilder") || "{}"); - const ausweisart: Enums.Ausweisart = params.get("ausweisart") + const ausweisart: Enums.Ausweisart = JSON.parse(params.get("ausweisart") || "") let user: BenutzerClient = {};