From 4732ecb770ed3d4a0ac7045dde32f34f2062b199 Mon Sep 17 00:00:00 2001
From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com>
Date: Thu, 19 Jun 2025 11:48:45 -0700
Subject: [PATCH] Added time Ban and penalty
---
apps/dispatch-server/routes/aircraft.ts | 19 +-
apps/dispatch-server/routes/dispatcher.ts | 19 +-
apps/dispatch/app/_components/Error.tsx | 18 +-
.../_components/customToasts/AdminMessage.tsx | 5 +-
.../app/_components/navbar/AdminPanel.tsx | 178 ++++++++++++++----
apps/dispatch/app/_querys/aircrafts.ts | 14 +-
apps/dispatch/app/_querys/dispatcher.ts | 14 +-
apps/dispatch/app/dispatch/layout.tsx | 21 +++
apps/dispatch/app/pilot/layout.tsx | 21 +++
apps/hub/app/(app)/_components/Penalty.tsx | 36 ++++
apps/hub/app/(app)/page.tsx | 2 +
packages/database/prisma/json/SocketEvents.ts | 1 +
.../database/prisma/schema/penalty.prisma | 23 +++
packages/database/prisma/schema/report.prisma | 10 +-
packages/database/prisma/schema/user.prisma | 2 +
15 files changed, 327 insertions(+), 56 deletions(-)
create mode 100644 apps/hub/app/(app)/_components/Penalty.tsx
create mode 100644 packages/database/prisma/schema/penalty.prisma
diff --git a/apps/dispatch-server/routes/aircraft.ts b/apps/dispatch-server/routes/aircraft.ts
index 7c1522b2..4f37b90a 100644
--- a/apps/dispatch-server/routes/aircraft.ts
+++ b/apps/dispatch-server/routes/aircraft.ts
@@ -117,6 +117,8 @@ router.patch("/:id", async (req, res) => {
router.delete("/:id", async (req, res) => {
const { id } = req.params;
const bann = req.body?.bann as boolean;
+ const reason = req.body?.reason as string;
+ const until = req.body?.until as Date | null;
const requiredPermission = bann ? "ADMIN_USER" : "ADMIN_KICK";
@@ -146,14 +148,16 @@ router.delete("/:id", async (req, res) => {
io.to(`user:${aircraft.userId}`).emit("notification", {
type: "admin-message",
- message: "Verbindung durch einen Administrator getrennt",
+ message: `Du wurdest von ${getPublicUser(req.user).publicId} ${until ? `bis zum ${new Date(until).toLocaleString()} ` : ""} ${
+ status === "ban" ? "gebannt" : "gekickt"
+ }`,
status,
- data: { admin: getPublicUser(req.user) },
+ data: { admin: getPublicUser(req.user), reason },
} as AdminMessage);
io.in(`user:${aircraft.userId}`).disconnectSockets(true);
- if (bann) {
+ if (bann && !until) {
await prisma.user.update({
where: { id: aircraft.userId },
data: {
@@ -163,6 +167,15 @@ router.delete("/:id", async (req, res) => {
},
});
}
+ await prisma.penalty.create({
+ data: {
+ userId: aircraft.userId,
+ type: bann ? (until ? "TIME_BAN" : "BAN") : "KICK",
+ until: until ? new Date(until) : null,
+ reason: reason,
+ createdUserId: req.user.id,
+ },
+ });
res.status(204).send();
} catch (error) {
diff --git a/apps/dispatch-server/routes/dispatcher.ts b/apps/dispatch-server/routes/dispatcher.ts
index 61f85e29..15a1a897 100644
--- a/apps/dispatch-server/routes/dispatcher.ts
+++ b/apps/dispatch-server/routes/dispatcher.ts
@@ -34,6 +34,8 @@ import { Request, Response } from "express";
router.delete("/:id", async (req, res) => {
const { id } = req.params;
const bann = req.body?.bann as boolean;
+ const reason = req.body?.reason as string;
+ const until = req.body?.until as Date | null;
const requiredPermission = bann ? "ADMIN_USER" : "ADMIN_KICK";
@@ -63,14 +65,16 @@ router.delete("/:id", async (req, res) => {
io.to(`user:${dispatcher.userId}`).emit("notification", {
type: "admin-message",
- message: "Verbindung durch einen Administrator getrennt",
+ message: `Du wurdest von ${getPublicUser(req.user).publicId} ${until ? `bis zum ${new Date(until).toLocaleString()} ` : ""} ${
+ status === "ban" ? "gebannt" : "gekickt"
+ }`,
status,
- data: { admin: getPublicUser(req.user) },
+ data: { admin: getPublicUser(req.user), reason },
} as AdminMessage);
io.in(`user:${dispatcher.userId}`).disconnectSockets(true);
- if (bann) {
+ if (bann && !until) {
await prisma.user.update({
where: { id: dispatcher.userId },
data: {
@@ -80,6 +84,15 @@ router.delete("/:id", async (req, res) => {
},
});
}
+ await prisma.penalty.create({
+ data: {
+ userId: dispatcher.userId,
+ type: bann ? (until ? "TIME_BAN" : "BAN") : "KICK",
+ until: until ? new Date(until) : null,
+ reason: reason,
+ createdUserId: req.user.id,
+ },
+ });
res.status(204).send();
} catch (error) {
diff --git a/apps/dispatch/app/_components/Error.tsx b/apps/dispatch/app/_components/Error.tsx
index 8386b58a..be04041e 100644
--- a/apps/dispatch/app/_components/Error.tsx
+++ b/apps/dispatch/app/_components/Error.tsx
@@ -2,13 +2,25 @@
import { useEffect } from "react";
-export const Error = ({ statusCode, title }: { statusCode: number; title: string }) => {
+export const Error = ({
+ statusCode,
+ title,
+ description,
+}: {
+ statusCode: number;
+ title: string;
+ description?: string;
+}) => {
return (
{statusCode}
-
Oh nein! Ein Fehler ist aufgetreten.
-
{title || "Ein unerwarteter Fehler ist aufgetreten."}
+
+ {title ? title : "Oh nein! Ein Fehler ist aufgetreten."}
+
+
+ {description || "Ein unerwarteter Fehler ist aufgetreten."}
+
diff --git a/apps/dispatch/app/_components/customToasts/AdminMessage.tsx b/apps/dispatch/app/_components/customToasts/AdminMessage.tsx
index 79e88b38..1e805f01 100644
--- a/apps/dispatch/app/_components/customToasts/AdminMessage.tsx
+++ b/apps/dispatch/app/_components/customToasts/AdminMessage.tsx
@@ -19,10 +19,9 @@ export const AdminMessageToast = ({ event, t }: { event: AdminMessage; t: Toast
event.status == "kick" && "text-yellow-500 ",
)}
>
- Du wurdes durch den Admin {event.data?.admin.publicId}{" "}
- {event.status == "ban" ? "gebannt" : "gekickt"}!
+ {event.message}
-
{event.message}
+
{event.data?.reason}