Dashboard, Datenblatt usw.
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
---
|
||||
import AusweisLayout from "#layouts/AusweisLayoutDaten.astro";
|
||||
import { AufnahmeClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
||||
import { createCaller } from "../../../astro-typesafe-api-caller.js";
|
||||
import { createCaller } from "../../astro-typesafe-api-caller.js";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken.js";
|
||||
import GEGNachweisVerbrauchsausweisWohnenModule from "#modules/angebot-anfragen/GEGNachweisVerbrauchsausweisWohnenModule.svelte";
|
||||
@@ -54,6 +54,7 @@ export const PUT = defineApiRoute({
|
||||
uid: aufnahme.uid,
|
||||
},
|
||||
},
|
||||
geg_anfrage: true
|
||||
},
|
||||
select: {
|
||||
uid: true,
|
||||
|
||||
@@ -2,28 +2,26 @@
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken.js";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
import { APIRoute } from "astro";
|
||||
import { APIError, defineApiRoute } from "astro-typesafe-api/server";
|
||||
import * as fs from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
export const GET = defineApiRoute({
|
||||
async fetch(input, context, transfer) {
|
||||
const { uid } = context.params
|
||||
const token = context.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
|
||||
export const GET: APIRoute = async (Astro) => {
|
||||
const { uid } = Astro.params
|
||||
const token = Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value;
|
||||
|
||||
if (!token) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Invalid access token"
|
||||
return new Response(null, {
|
||||
status: 400
|
||||
})
|
||||
}
|
||||
|
||||
const valid = validateAccessTokenServer(context);
|
||||
const valid = validateAccessTokenServer(Astro);
|
||||
|
||||
if (!valid) {
|
||||
throw new APIError({
|
||||
code: "BAD_REQUEST",
|
||||
message: "Invalid access token"
|
||||
return new Response(null, {
|
||||
status: 401
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,21 +32,18 @@ export const GET = defineApiRoute({
|
||||
})
|
||||
|
||||
if (!image) {
|
||||
throw new APIError({
|
||||
code: "NOT_FOUND",
|
||||
message: "Image could not be found."
|
||||
return new Response(null, {
|
||||
status: 404
|
||||
})
|
||||
}
|
||||
|
||||
const path = fileURLToPath(new URL(`../../../persistent/images/${image.uid}.webp`, import.meta.url))
|
||||
const base64 = fs.readFileSync(path, "base64")
|
||||
|
||||
const buffer = Buffer.from(base64, "base64");
|
||||
const buffer = fs.readFileSync(path)
|
||||
|
||||
return new Response(buffer, {
|
||||
status: 200,
|
||||
headers: {
|
||||
"Content-Type": "image/webp"
|
||||
}
|
||||
});
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
---
|
||||
import { AufnahmeClient, BenutzerClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
||||
import UserLayout from "#layouts/UserLayout.astro";
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import { omit } from "#lib/helpers";
|
||||
import DashboardAusweisePruefenModule from "#modules/Dashboard/DashboardAusweisePruefenModule.svelte";
|
||||
import { Enums, prisma } from "@ibcornelsen/database/server";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller";
|
||||
@@ -44,15 +45,10 @@ const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
|
||||
}
|
||||
})
|
||||
|
||||
function omit(key: string, obj: Record<string, any>) {
|
||||
const { [key]: omitted, ...rest } = obj;
|
||||
return rest;
|
||||
}
|
||||
|
||||
const reformedAusweise = ausweise.map(ausweis => ({
|
||||
ausweis: omit("aufnahme", ausweis) as VerbrauchsausweisWohnenClient,
|
||||
aufnahme: omit("objekt", omit("events", ausweis.aufnahme)) as AufnahmeClient,
|
||||
objekt: omit("bilder", ausweis.aufnahme.objekt) as ObjektClient,
|
||||
ausweis: omit(ausweis, ["aufnahme"]) as VerbrauchsausweisWohnenClient,
|
||||
aufnahme: omit(omit(ausweis.aufnahme, ["events"]), ["objekt"]) as AufnahmeClient,
|
||||
objekt: omit(ausweis.aufnahme.objekt, ["bilder"]) as ObjektClient,
|
||||
bilder: ausweis.aufnahme.objekt.bilder as unknown as UploadedGebaeudeBild[],
|
||||
events: ausweis.aufnahme.events
|
||||
}))
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import UserLayout from "../../../layouts/UserLayout.astro";
|
||||
import UserLayout from "../../../layouts/DashboardLayout.astro";
|
||||
import DashboardPDFDesignerModule from "../../../modules/Dashboard/DashboardPDFDesignerModule.svelte";
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
import { createCaller } from "#lib/caller";
|
||||
import UserLayout from "../../../layouts/UserLayout.astro";
|
||||
import UserLayout from "../../../layouts/DashboardLayout.astro";
|
||||
import DashboardPDFViewerModule from "../../../modules/Dashboard/DashboardPDFViewerModule.svelte";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import UserLayout from "../../../layouts/UserLayout.astro";
|
||||
import UserLayout from "../../../layouts/DashboardLayout.astro";
|
||||
import DashboardAusweiseModule from "#modules/Dashboard/DashboardAusweiseModule.svelte";
|
||||
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
---
|
||||
import UserLayout from "#layouts/UserLayout.astro";
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import { createCaller } from "#lib/caller";
|
||||
import DashboardEinstellungenModule from "#modules/Dashboard/DashboardEinstellungenModule.svelte";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
|
||||
@@ -3,8 +3,8 @@ import { createCaller } from "../../astro-typesafe-api-caller.js";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
import DashboardModule from "#modules/Dashboard/DashboardModule.svelte";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import Layout from "#layouts/Layout.astro";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
import DashboardLayout from "#layouts/DashboardLayout.astro";
|
||||
|
||||
const accessTokenValid = await validateAccessTokenServer(Astro);
|
||||
|
||||
@@ -33,10 +33,18 @@ const objekte = await prisma.objekt.findMany({
|
||||
take: 10,
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
aufnahmen: {
|
||||
include: {
|
||||
bedarfsausweis_wohnen: true,
|
||||
verbrauchsausweis_gewerbe: true,
|
||||
verbrauchsausweis_wohnen: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
---
|
||||
|
||||
<Layout title="Dashboard">
|
||||
<DashboardLayout title="Dashboard" {user}>
|
||||
<DashboardModule {user} {objekte} />
|
||||
</Layout>
|
||||
</DashboardLayout>
|
||||
54
src/pages/dashboard/objekt/[uid].astro
Normal file
54
src/pages/dashboard/objekt/[uid].astro
Normal file
@@ -0,0 +1,54 @@
|
||||
---
|
||||
import { createCaller } from "../../../astro-typesafe-api-caller.js";
|
||||
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
|
||||
import DashboardModule from "#modules/Dashboard/DashboardModule.svelte";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import Layout from "#layouts/Layout.astro";
|
||||
import { prisma } from "@ibcornelsen/database/server";
|
||||
import DashboardObjektModule from "#modules/Dashboard/DashboardObjektModule.svelte";
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
|
||||
const { uid } = Astro.params;
|
||||
|
||||
const accessTokenValid = await validateAccessTokenServer(Astro);
|
||||
|
||||
if (!accessTokenValid) {
|
||||
return Astro.redirect("/auth/login")
|
||||
}
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
|
||||
const user = await caller.user.self.GET.fetch(undefined, {
|
||||
headers: {
|
||||
"Authorization": `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
return Astro.redirect("/auth/login")
|
||||
}
|
||||
|
||||
const objekt = await prisma.objekt.findUnique({
|
||||
where: {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
},
|
||||
uid
|
||||
},
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
aufnahmen: {
|
||||
include: {
|
||||
bedarfsausweis_wohnen: true,
|
||||
verbrauchsausweis_gewerbe: true,
|
||||
verbrauchsausweis_wohnen: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
---
|
||||
|
||||
<UserLayout title="Dashboard" {user}>
|
||||
<DashboardObjektModule {user} {objekt} client:only/>
|
||||
</UserLayout>
|
||||
@@ -1,92 +0,0 @@
|
||||
---
|
||||
import { AufnahmeClient, BenutzerClient, getAusweisartFromUUID, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import { pdfDatenblattVerbrauchsausweisWohnen } from "#lib/pdf/pdfDatenblattVerbrauchsausweisWohnen";
|
||||
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen";
|
||||
import { Enums } from "@ibcornelsen/database/client";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller";
|
||||
|
||||
const base64Ausweis = Astro.url.searchParams.get("ausweis");
|
||||
const base64Aufnahme = Astro.url.searchParams.get("aufnahme");
|
||||
const base64Objekt = Astro.url.searchParams.get("objekt");
|
||||
const base64Bilder = Astro.url.searchParams.get("bilder");
|
||||
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||
let objekt: ObjektClient = {} as ObjektClient;
|
||||
let benutzer: BenutzerClient = {} as BenutzerClient;
|
||||
let bilder: UploadedGebaeudeBild[] = []
|
||||
if (base64Ausweis && base64Aufnahme && base64Objekt && base64Bilder) {
|
||||
ausweis = JSON.parse(Buffer.from(base64Ausweis, "base64").toString("utf-8")) as VerbrauchsausweisWohnenClient;
|
||||
objekt = JSON.parse(Buffer.from(base64Objekt, "base64").toString("utf-8")) as ObjektClient;
|
||||
aufnahme = JSON.parse(Buffer.from(base64Aufnahme, "base64").toString("utf-8")) as AufnahmeClient;
|
||||
bilder = JSON.parse(Buffer.from(base64Bilder, "base64").toString("utf-8")) as UploadedGebaeudeBild[];
|
||||
} else {
|
||||
const uidAusweis = Astro.url.searchParams.get("uid");
|
||||
|
||||
if (!uidAusweis) {
|
||||
return Astro.redirect("/404");
|
||||
}
|
||||
|
||||
const ausweisart = getAusweisartFromUUID(uidAusweis)
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: uidAusweis
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||
ausweis = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: uidAusweis
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!ausweis) {
|
||||
return Astro.redirect("/");
|
||||
}
|
||||
|
||||
aufnahme = await caller.aufnahme._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: ausweis.uid_aufnahme
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
objekt = await caller.objekt._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: ausweis.uid_objekt
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
benutzer = await caller.user.self.GET.fetch(undefined, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const pdf = await pdfDatenblattVerbrauchsausweisWohnen(ausweis, aufnahme, objekt, benutzer);
|
||||
|
||||
|
||||
return new Response(pdf, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
---
|
||||
127
src/pages/pdf/datenblatt.ts
Normal file
127
src/pages/pdf/datenblatt.ts
Normal file
@@ -0,0 +1,127 @@
|
||||
import { AufnahmeClient, BenutzerClient, getAusweisartFromUUID, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisGewerbeClient, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types.js";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
|
||||
import { pdfDatenblattVerbrauchsausweisGewerbe } from "#lib/pdf/pdfDatenblattVerbrauchsausweisGewerbe.js";
|
||||
import { pdfDatenblattVerbrauchsausweisWohnen } from "#lib/pdf/pdfDatenblattVerbrauchsausweisWohnen.js";
|
||||
import { pdfVerbrauchsausweisGewerbe } from "#lib/pdf/pdfVerbrauchsausweisGewerbe.js";
|
||||
import { pdfVerbrauchsausweisWohnen } from "#lib/pdf/pdfVerbrauchsausweisWohnen.js";
|
||||
import { Enums } from "@ibcornelsen/database/client";
|
||||
import { APIRoute } from "astro";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller.js";
|
||||
|
||||
export const GET: APIRoute = async (Astro) => {
|
||||
const uidAusweis = Astro.url.searchParams.get("uid");
|
||||
|
||||
if (!uidAusweis) {
|
||||
return Astro.redirect("/404")
|
||||
}
|
||||
|
||||
const ausweisart = getAusweisartFromUUID(uidAusweis)
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
|
||||
let ausweis: VerbrauchsausweisWohnenClient | VerbrauchsausweisGewerbeClient | null = null;
|
||||
let aufnahme: AufnahmeClient = {} as AufnahmeClient;
|
||||
let objekt: ObjektClient = {} as ObjektClient;
|
||||
let user: BenutzerClient = {} as BenutzerClient;
|
||||
let bilder: UploadedGebaeudeBild[] = []
|
||||
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
ausweis = await caller["verbrauchsausweis-wohnen"]._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: uidAusweis
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||
ausweis = await caller["verbrauchsausweis-gewerbe"]._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: uidAusweis
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
if (!ausweis) {
|
||||
return Astro.redirect("/");
|
||||
}
|
||||
|
||||
aufnahme = await caller.aufnahme._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: ausweis.uid_aufnahme
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
objekt = await caller.objekt._uid.GET.fetch(undefined, {
|
||||
params: {
|
||||
uid: ausweis.uid_objekt
|
||||
},
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
user = await caller.user.self.GET.fetch(undefined, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
|
||||
let pdf: Uint8Array<ArrayBufferLike> | null = null;
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
pdf = await pdfVerbrauchsausweisWohnen(ausweis as VerbrauchsausweisWohnenClient, aufnahme, objekt, bilder, user);
|
||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||
pdf = await pdfVerbrauchsausweisGewerbe(ausweis as VerbrauchsausweisGewerbeClient, aufnahme, objekt, bilder, user);
|
||||
}
|
||||
|
||||
return new Response(pdf, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export const POST: APIRoute = async (Astro) => {
|
||||
const body = await Astro.request.text();
|
||||
const params = new URLSearchParams(body);
|
||||
|
||||
const caller = createCaller(Astro);
|
||||
|
||||
const ausweis = JSON.parse(params.get("ausweis") || "{}");
|
||||
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")
|
||||
|
||||
let user: BenutzerClient = {};
|
||||
|
||||
try {
|
||||
user = await caller.user.self.GET.fetch(undefined, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
|
||||
let pdf: Uint8Array<ArrayBufferLike> | null = null;
|
||||
if (ausweisart === Enums.Ausweisart.VerbrauchsausweisWohnen) {
|
||||
pdf = await pdfDatenblattVerbrauchsausweisWohnen(ausweis, aufnahme, objekt, bilder);
|
||||
} else if (ausweisart === Enums.Ausweisart.VerbrauchsausweisGewerbe) {
|
||||
pdf = await pdfDatenblattVerbrauchsausweisGewerbe(ausweis, aufnahme, objekt, bilder);
|
||||
}
|
||||
|
||||
return new Response(pdf, {
|
||||
headers: {
|
||||
"Content-Type": "application/pdf",
|
||||
},
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user