Dashboard, Datenblatt usw.
This commit is contained in:
59
src/pages/dashboard/admin/ausweise-pruefen.astro
Normal file
59
src/pages/dashboard/admin/ausweise-pruefen.astro
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
import { AufnahmeClient, BenutzerClient, ObjektClient, UploadedGebaeudeBild, VerbrauchsausweisWohnenClient } from "#components/Ausweis/types";
|
||||
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";
|
||||
|
||||
const caller = createCaller(Astro)
|
||||
|
||||
|
||||
let user: BenutzerClient;
|
||||
try {
|
||||
user = (await caller.user.self.GET.fetch(undefined, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${Astro.cookies.get(API_ACCESS_TOKEN_COOKIE_NAME)?.value}`
|
||||
}
|
||||
})) || {} as BenutzerClient;
|
||||
} catch(e) {
|
||||
return Astro.redirect("/auth/login")
|
||||
}
|
||||
|
||||
if (user.rolle !== Enums.BenutzerRolle.ADMIN) {
|
||||
return Astro.redirect("/dashboard")
|
||||
}
|
||||
|
||||
const ausweise = await prisma.verbrauchsausweisWohnen.findMany({
|
||||
where: {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
}
|
||||
},
|
||||
include: {
|
||||
aufnahme: {
|
||||
include: {
|
||||
objekt: {
|
||||
include: {
|
||||
bilder: true,
|
||||
}
|
||||
},
|
||||
events: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const reformedAusweise = ausweise.map(ausweis => ({
|
||||
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
|
||||
}))
|
||||
---
|
||||
|
||||
<UserLayout title="Ausweise Prüfen" {user}>
|
||||
<DashboardAusweisePruefenModule ausweise={reformedAusweise} client:load></DashboardAusweisePruefenModule>
|
||||
</UserLayout>
|
||||
Reference in New Issue
Block a user