82 lines
1.7 KiB
Plaintext
82 lines
1.7 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: {
|
|
include: {
|
|
rechnung: true
|
|
}
|
|
},
|
|
verbrauchsausweise_gewerbe: {
|
|
include: {
|
|
rechnung: true
|
|
}
|
|
},
|
|
verbrauchsausweise_wohnen: {
|
|
include: {
|
|
rechnung: true
|
|
}
|
|
},
|
|
bedarfsausweise_gewerbe: {
|
|
include: {
|
|
rechnung: true
|
|
}
|
|
},
|
|
geg_nachweise_gewerbe: {
|
|
include: {
|
|
rechnung: true
|
|
}
|
|
},
|
|
geg_nachweise_wohnen: {
|
|
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> |