Files
online-energieausweis/src/pages/dashboard/aufnahme/[id].astro
Moritz Utcke 05b31a4862 Dashboard
2025-04-21 16:15:47 -03:00

100 lines
1.9 KiB
Plaintext

---
import { createCaller } from "../../../astro-typesafe-api-caller.js";
import { validateAccessTokenServer } from "#server/lib/validateAccessToken";
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants.js";
import { Enums, prisma } from "#lib/server/prisma";
import UserLayout from "#layouts/DashboardLayout.astro";
import DashboardAufnahmeModule from "#modules/Dashboard/DashboardAufnahmeModule.svelte";
const { id } = 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 aufnahme = await prisma.aufnahme.findUnique({
where: user.rolle === Enums.BenutzerRolle.USER ? {
benutzer: {
id: user.id
},
id
} : { id },
include: {
objekt: true,
bilder: true,
unterlagen: true,
bedarfsausweise_wohnen: {
orderBy: {
updated_at: "desc"
},
include: {
rechnung: true
}
},
verbrauchsausweise_gewerbe: {
orderBy: {
updated_at: "desc"
},
include: {
rechnung: true
}
},
verbrauchsausweise_wohnen: {
orderBy: {
updated_at: "desc"
},
include: {
rechnung: true
}
},
bedarfsausweise_gewerbe: {
orderBy: {
updated_at: "desc"
},
include: {
rechnung: true
}
},
geg_nachweise_gewerbe: {
orderBy: {
updated_at: "desc"
},
include: {
rechnung: true
}
},
geg_nachweise_wohnen: {
orderBy: {
updated_at: "desc"
},
include: {
rechnung: true
}
},
events: true
}
})
if (!aufnahme) {
return Astro.redirect("/dashboard")
}
---
<UserLayout title="Dashboard" {user}>
<DashboardAufnahmeModule {user} {aufnahme} benutzer={user} objekt={aufnahme.objekt} client:load/>
</UserLayout>