"use server"; import { prisma } from "@repo/db"; import { getServerSession } from "api/auth/[...nextauth]/auth"; import { PlaneIcon } from "lucide-react"; export const PilotStats = async () => { return (
Einsätze geflogen
127
Du bist damit unter den top 5%!
Pilot Login Zeit
35h 12m
Mehr als 58% aller anderen User!
Christoph 31
War bisher dein Rettungsmittel der Wahl
87 Stationen warten noch auf dich!
); }; export const DispoStats = async () => { const session = await getServerSession(); if (!session) return null; const user = await prisma.user.findUnique({ where: { id: session.user.id }, }); const dispoSessions = await prisma.connectedDispatcher.findMany({ where: { userId: user?.id, logoutTime: { not: null, }, }, select: { loginTime: true, logoutTime: true, }, }); const mostDispatchedStationIds = await prisma.mission.groupBy({ where: { createdUserId: user?.id, }, by: ["missionStationIds"], orderBy: { _count: { missionStationIds: "desc", }, }, take: 1, _count: { missionStationIds: true, }, }); let mostDispatchedStation = null; if (mostDispatchedStationIds[0]?.missionStationIds[0]) { mostDispatchedStation = await prisma.station.findUnique({ where: { id: parseInt(mostDispatchedStationIds[0]?.missionStationIds[0]), }, }); } const totalDispatchedMissions = await prisma.mission.count({ where: { createdUserId: user?.id, }, }); const totalDispoTime = dispoSessions.reduce((acc, session) => { const logoffTime = new Date(session.logoutTime!).getTime(); const logonTime = new Date(session.loginTime).getTime(); return acc + (logoffTime - logonTime); }, 0); const hours = Math.floor(totalDispoTime / (1000 * 60 * 60)); const minutes = Math.floor((totalDispoTime % (1000 * 60 * 60)) / (1000 * 60)); return (
Einsätze disponiert
{totalDispatchedMissions}
Du bist damit unter den top 9%!
Disponent Login Zeit
{hours}h {minutes}m
Mehr als 69% aller anderen User!
{mostDispatchedStation && (
{mostDispatchedStation?.bosCallsign}
Wurde von dir am meisten Disponiert
{mostDispatchedStationIds[0]?._count.missionStationIds} Einsätze
)}
); };