Admin Tools
This commit is contained in:
@@ -1,53 +1,3 @@
|
||||
---
|
||||
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 { Enums, prisma } from "#lib/server/prisma";
|
||||
import DashboardLayout from "#layouts/DashboardLayout.astro";
|
||||
|
||||
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 objekte = await prisma.objekt.findMany({
|
||||
where: user.rolle === Enums.BenutzerRolle.USER ? {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
}
|
||||
} : {},
|
||||
take: 25,
|
||||
orderBy: {
|
||||
erstellungsdatum: "desc"
|
||||
},
|
||||
include: {
|
||||
aufnahmen: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
bedarfsausweise_wohnen: true,
|
||||
verbrauchsausweise_gewerbe: true,
|
||||
verbrauchsausweise_wohnen: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
---
|
||||
|
||||
<DashboardLayout title="Dashboard" {user}>
|
||||
<DashboardModule {user} {objekte} client:load />
|
||||
</DashboardLayout>
|
||||
return Astro.redirect("/dashboard/objekte/1", 301);
|
||||
---
|
||||
58
src/pages/dashboard/objekte/[page].astro
Normal file
58
src/pages/dashboard/objekte/[page].astro
Normal file
@@ -0,0 +1,58 @@
|
||||
---
|
||||
import UserLayout from "#layouts/DashboardLayout.astro";
|
||||
import { API_ACCESS_TOKEN_COOKIE_NAME } from "#lib/constants";
|
||||
import { Enums, prisma } from "#lib/server/prisma";
|
||||
import { createCaller } from "src/astro-typesafe-api-caller";
|
||||
import DashboardModule from "#modules/Dashboard/DashboardModule.svelte";
|
||||
|
||||
const caller = createCaller(Astro)
|
||||
|
||||
const params = Astro.params;
|
||||
const page = Number(params.page)
|
||||
|
||||
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 totalPages = await prisma.objekt.count({
|
||||
where: user.rolle === Enums.BenutzerRolle.USER ? {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
}
|
||||
} : {}
|
||||
})
|
||||
|
||||
const objekte = await prisma.objekt.findMany({
|
||||
where: user.rolle === Enums.BenutzerRolle.USER ? {
|
||||
benutzer: {
|
||||
uid: user.uid
|
||||
}
|
||||
} : {},
|
||||
orderBy: {
|
||||
erstellungsdatum: "desc"
|
||||
},
|
||||
include: {
|
||||
aufnahmen: {
|
||||
include: {
|
||||
bilder: true,
|
||||
unterlagen: true,
|
||||
bedarfsausweise_wohnen: true,
|
||||
verbrauchsausweise_gewerbe: true,
|
||||
verbrauchsausweise_wohnen: true
|
||||
}
|
||||
}
|
||||
},
|
||||
take: 25,
|
||||
skip: (page - 1) * 25
|
||||
})
|
||||
---
|
||||
|
||||
<UserLayout title="Ausweise Prüfen" {user}>
|
||||
<DashboardModule {user} {objekte} totalPages={Math.ceil(totalPages / 25)} page={page} client:load />
|
||||
</UserLayout>
|
||||
Reference in New Issue
Block a user