From be94bd482c311fd97935fc65639b658fc63fa5b7 Mon Sep 17 00:00:00 2001 From: Moritz Utcke Date: Tue, 1 Apr 2025 09:43:43 -0300 Subject: [PATCH] Datenblatt und Verbrauchsausweis verbessert --- src/lib/server/db.ts | 18 ++++++++++- src/pages/pdf/ansichtsausweis.ts | 50 ++++++----------------------- src/pages/pdf/datenblatt.ts | 54 +++++++------------------------- 3 files changed, 39 insertions(+), 83 deletions(-) diff --git a/src/lib/server/db.ts b/src/lib/server/db.ts index 151da318..a1d700cc 100644 --- a/src/lib/server/db.ts +++ b/src/lib/server/db.ts @@ -1,4 +1,4 @@ -import { Aufnahme, BedarfsausweisGewerbe, Bild, Objekt, prisma, Unterlage, VerbrauchsausweisWohnen } from "./prisma.js"; +import { Aufnahme, BedarfsausweisGewerbe, BedarfsausweisWohnen, Bild, Objekt, prisma, Unterlage, VerbrauchsausweisGewerbe, VerbrauchsausweisWohnen } from "./prisma.js"; export async function getVerbrauchsausweisWohnen(id: string): Promise { return await prisma.verbrauchsausweisWohnen.findUnique({ @@ -8,6 +8,22 @@ export async function getVerbrauchsausweisWohnen(id: string): Promise { + return await prisma.verbrauchsausweisGewerbe.findUnique({ + where: { + id + } + }) +} + +export async function getBedarfsausweisWohnen(id: string): Promise { + return await prisma.bedarfsausweisWohnen.findUnique({ + where: { + id + } + }) +} + export async function getBedarfsausweisGewerbe(id: string): Promise { return await prisma.bedarfsausweisGewerbe.findUnique({ where: { diff --git a/src/pages/pdf/ansichtsausweis.ts b/src/pages/pdf/ansichtsausweis.ts index e9c50878..7ef8c4eb 100644 --- a/src/pages/pdf/ansichtsausweis.ts +++ b/src/pages/pdf/ansichtsausweis.ts @@ -6,9 +6,11 @@ import { Enums } from "#lib/client/prisma.js"; import { APIRoute } from "astro"; import { createCaller } from "src/astro-typesafe-api-caller.js"; import { getS3File } from "#lib/s3.js"; +import { getVerbrauchsausweisWohnen, getVerbrauchsausweisGewerbe, getAufnahme, getObjekt, getBilder } from "#lib/server/db.js"; +import { getCurrentUser } from "#lib/server/user.js"; export const GET: APIRoute = async (Astro) => { - const ausweis_id = Astro.url.searchParams.get("uid"); + const ausweis_id = Astro.url.searchParams.get("id"); if (!ausweis_id) { return new Response(null, { status: 404 }); @@ -16,8 +18,6 @@ export const GET: APIRoute = async (Astro) => { const ausweisart = getAusweisartFromId(ausweis_id) - const caller = createCaller(Astro); - let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null; let aufnahme: AufnahmeClient = {} as AufnahmeClient; let objekt: ObjektClient = {} as ObjektClient; @@ -25,23 +25,9 @@ export const GET: APIRoute = async (Astro) => { let bilder: UploadedGebaeudeBild[] = [] if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) { - ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(undefined, { - params: { - id: ausweis_id - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + ausweis = await getVerbrauchsausweisWohnen(ausweis_id) } else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) { - ausweis = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(undefined, { - params: { - id: ausweis_id - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + ausweis = await getVerbrauchsausweisGewerbe(ausweis_id) } @@ -49,29 +35,13 @@ export const GET: APIRoute = async (Astro) => { return new Response(null, { status: 404 }); } - aufnahme = await caller.aufnahme._id.GET.fetch(undefined, { - params: { - id: ausweis.aufnahme_id - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + aufnahme = await getAufnahme(ausweis.aufnahme_id) - objekt = await caller.objekt._id.GET.fetch(undefined, { - params: { - id: ausweis.objekt_id - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + objekt = await getObjekt(aufnahme.objekt_id) - user = await caller.user.self.GET.fetch(undefined, { - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + bilder = await getBilder(ausweis.aufnahme_id) + + user = await getCurrentUser(Astro) let pdf: Uint8Array | null = null; if (ausweis.alte_ausweis_id) { diff --git a/src/pages/pdf/datenblatt.ts b/src/pages/pdf/datenblatt.ts index d67ece19..c3df0d51 100644 --- a/src/pages/pdf/datenblatt.ts +++ b/src/pages/pdf/datenblatt.ts @@ -8,17 +8,17 @@ import { Enums } from "#lib/client/prisma.js"; import { APIRoute } from "astro"; import { createCaller } from "src/astro-typesafe-api-caller.js"; import { getS3File } from "#lib/s3.js"; +import { getAufnahme, getBilder, getObjekt, getVerbrauchsausweisGewerbe, getVerbrauchsausweisWohnen } from "#lib/server/db.js"; +import { getCurrentUser } from "#lib/server/user.js"; export const GET: APIRoute = async (Astro) => { - const uidAusweis = Astro.url.searchParams.get("uid"); + const ausweis_id = Astro.url.searchParams.get("id"); - if (!uidAusweis) { + if (!ausweis_id) { return new Response(null, { status: 404 }); } - const ausweisart = getAusweisartFromId(uidAusweis) - - const caller = createCaller(Astro); + const ausweisart = getAusweisartFromId(ausweis_id) let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null; let aufnahme: AufnahmeClient = {} as AufnahmeClient; @@ -27,23 +27,9 @@ export const GET: APIRoute = async (Astro) => { let bilder: UploadedGebaeudeBild[] = [] if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) { - ausweis = await caller["verbrauchsausweis-wohnen"]._id.GET.fetch(undefined, { - params: { - id: uidAusweis - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + ausweis = await getVerbrauchsausweisWohnen(ausweis_id) } else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) { - ausweis = await caller["verbrauchsausweis-gewerbe"]._id.GET.fetch(undefined, { - params: { - id: uidAusweis - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + ausweis = await getVerbrauchsausweisGewerbe(ausweis_id) } @@ -51,29 +37,13 @@ export const GET: APIRoute = async (Astro) => { return new Response(null, { status: 404 }); } - aufnahme = await caller.aufnahme._id.GET.fetch(undefined, { - params: { - id: ausweis.aufnahme_id - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + aufnahme = await getAufnahme(ausweis.aufnahme_id) - objekt = await caller.objekt._id.GET.fetch(undefined, { - params: { - id: ausweis.objekt_id - }, - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + objekt = await getObjekt(aufnahme.objekt_id) - user = await caller.user.self.GET.fetch(undefined, { - headers: { - Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}` - } - }); + bilder = await getBilder(ausweis.aufnahme_id) + + user = await getCurrentUser(Astro) let pdf: Uint8Array | null = null; if (ausweis.alte_ausweis_id) {