From 577a18d5956cc13ce94ee011fd90dec40fef9bfc Mon Sep 17 00:00:00 2001
From: PxlLoewe <72106766+PxlLoewe@users.noreply.github.com>
Date: Wed, 25 Jun 2025 17:09:41 -0700
Subject: [PATCH] added user casacde delete
---
.vscode/settings.json | 20 ++-------
apps/hub/app/(app)/_components/Penalty.tsx | 20 +++++----
.../hub/app/(app)/admin/penalty/[id]/page.tsx | 10 +++--
apps/hub/app/(app)/admin/penalty/columns.tsx | 5 ++-
.../(app)/admin/report/_components/form.tsx | 10 +++--
packages/database/prisma/schema/auth.prisma | 44 +------------------
.../database/prisma/schema/chatMessage.prisma | 4 +-
.../prisma/schema/connectedAircraft.prisma | 4 +-
.../prisma/schema/connectedDispatcher.prisma | 2 +-
packages/database/prisma/schema/event.prisma | 2 +-
.../database/prisma/schema/mission.prisma | 4 +-
.../database/prisma/schema/penalty.prisma | 8 ++--
.../database/prisma/schema/positionLog.prisma | 2 +-
packages/database/prisma/schema/report.prisma | 6 +--
14 files changed, 47 insertions(+), 94 deletions(-)
diff --git a/.vscode/settings.json b/.vscode/settings.json
index a807eb19..07bb728a 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -3,7 +3,8 @@
"files.autoSave": "off",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": ["source.formatDocument", "source.fixAll.eslint"],
- "eslint.lintTask.enable": true,
+ "typescript.validate.enable": true,
+ "typescript.tsserver.experimental.enableProjectDiagnostics": true,
"restoreTerminals.terminals": [
{
"splitTerminals": [
@@ -17,20 +18,5 @@
"typescript.tsdk": "node_modules/typescript/lib",
"[prisma]": {
"editor.defaultFormatter": "Prisma.prisma"
- },
- "[xml]": {
- "editor.defaultFormatter": "redhat.vscode-xml"
- },
- "sqltools.connections": [
- {
- "previewLimit": 50,
- "server": "localhost",
- "port": 5432,
- "driver": "PostgreSQL",
- "name": "Persistant-Data",
- "database": "var",
- "username": "persistant-data",
- "password": "persistant-data-pw"
- }
- ]
+ }
}
diff --git a/apps/hub/app/(app)/_components/Penalty.tsx b/apps/hub/app/(app)/_components/Penalty.tsx
index f3f1fc61..5506063c 100644
--- a/apps/hub/app/(app)/_components/Penalty.tsx
+++ b/apps/hub/app/(app)/_components/Penalty.tsx
@@ -47,10 +47,12 @@ export const Penalty = async () => {
Grund: {openTimeban[0].reason}
-
- Admin:{" "}
- {getPublicUser(openTimeban[0].CreatedUser).fullName}
-
+ {openTimeban[0].CreatedUser && (
+
+ Admin:{" "}
+ {getPublicUser(openTimeban[0].CreatedUser).fullName}
+
+ )}
)}
{session?.user.isBanned && (
@@ -68,10 +70,12 @@ export const Penalty = async () => {
Grund: {openBans[0].reason || "Keine Begründung gefunden"}
-
- Admin:{" "}
- {getPublicUser(openBans[0].CreatedUser).fullName || "Keine Admin gefunden"}
-
+ {openBans[0].CreatedUser && (
+
+ Admin:{" "}
+ {getPublicUser(openBans[0].CreatedUser).fullName}
+
+ )}
>
)}
diff --git a/apps/hub/app/(app)/admin/penalty/[id]/page.tsx b/apps/hub/app/(app)/admin/penalty/[id]/page.tsx
index b7f31691..c77fecbe 100644
--- a/apps/hub/app/(app)/admin/penalty/[id]/page.tsx
+++ b/apps/hub/app/(app)/admin/penalty/[id]/page.tsx
@@ -43,10 +43,12 @@ export default async function Page({ params }: { params: Promise<{ id: string }>
Benutzer: {penalty.User.firstname}{" "}
{penalty.User.lastname} ({penalty.User.publicId})
-
- Erstellt von: {penalty.CreatedUser.firstname}{" "}
- {penalty.CreatedUser.lastname} ({penalty.CreatedUser.publicId})
-
+ {penalty.CreatedUser && (
+
+ Erstellt von: {penalty.CreatedUser.firstname}{" "}
+ {penalty.CreatedUser.lastname} ({penalty.CreatedUser.publicId})
+
+ )}
Typ: {penalty.type}
diff --git a/apps/hub/app/(app)/admin/penalty/columns.tsx b/apps/hub/app/(app)/admin/penalty/columns.tsx
index 837f84a8..9fb24087 100644
--- a/apps/hub/app/(app)/admin/penalty/columns.tsx
+++ b/apps/hub/app/(app)/admin/penalty/columns.tsx
@@ -8,7 +8,7 @@ import { de } from "date-fns/locale";
import { cn } from "../../../../helper/cn";
import { HobbyKnifeIcon } from "@radix-ui/react-icons";
-export const penaltyColumns: ColumnDef[] = [
+export const penaltyColumns: ColumnDef[] = [
{
accessorKey: "type",
header: "Typ",
@@ -59,7 +59,8 @@ export const penaltyColumns: ColumnDef[] = [
accessorKey: "CreatedUser",
header: "Bestraft durch",
cell: ({ row }) => {
- const user = row.getValue("CreatedUser") as User;
+ const user = row.original.CreatedUser;
+ if (!user) return "Unbekannt";
return `${user.firstname} ${user.lastname} (${user.publicId})`;
},
},
diff --git a/apps/hub/app/(app)/admin/report/_components/form.tsx b/apps/hub/app/(app)/admin/report/_components/form.tsx
index 7162ccc7..ece22062 100644
--- a/apps/hub/app/(app)/admin/report/_components/form.tsx
+++ b/apps/hub/app/(app)/admin/report/_components/form.tsx
@@ -19,8 +19,8 @@ export const ReportSenderInfo = ({
report,
}: {
report: IReport & {
- Reported?: User;
- Sender?: User;
+ Reported: User;
+ Sender: User | null;
};
}) => {
const { Reported, Sender } = report;
@@ -49,7 +49,8 @@ export const ReportAdmin = ({
}: {
report: IReport & {
Reported?: User;
- Sender?: User;
+ Sender: User | null;
+
Reviewer?: User | null;
};
}) => {
@@ -136,7 +137,8 @@ export const ReportPenalties = ({
}: {
report: IReport & {
Reported?: User;
- Sender?: User;
+ Sender: User | null;
+
Reviewer?: User | null;
};
}) => {
diff --git a/packages/database/prisma/schema/auth.prisma b/packages/database/prisma/schema/auth.prisma
index e4c9c73f..ccb7305c 100644
--- a/packages/database/prisma/schema/auth.prisma
+++ b/packages/database/prisma/schema/auth.prisma
@@ -1,45 +1,3 @@
-model Account {
- id Int @id @default(autoincrement())
- compoundId String @unique @map(name: "compound_id")
- userId Int @map(name: "user_id")
- providerType String @map(name: "provider_type")
- providerId String @map(name: "provider_id")
- providerAccountId String @map(name: "provider_account_id")
- refreshToken String? @map(name: "refresh_token")
- accessToken String? @map(name: "access_token")
- accessTokenExpires DateTime? @map(name: "access_token_expires")
- createdAt DateTime @default(now()) @map(name: "created_at")
- updatedAt DateTime @default(now()) @map(name: "updated_at")
-
- @@index([providerAccountId], name: "providerAccountId")
- @@index([providerId], name: "providerId")
- @@index([userId], name: "userId")
- @@map(name: "accounts")
-}
-
-model Session {
- id Int @id @default(autoincrement())
- userId Int @map(name: "user_id")
- expires DateTime
- sessionToken String @unique @map(name: "session_token")
- accessToken String @unique @map(name: "access_token")
- createdAt DateTime @default(now()) @map(name: "created_at")
- updatedAt DateTime @default(now()) @map(name: "updated_at")
-
- @@map(name: "sessions")
-}
-
-model VerificationRequest {
- id Int @id @default(autoincrement())
- identifier String
- token String @unique
- expires DateTime
- createdAt DateTime @default(now()) @map(name: "created_at")
- updatedAt DateTime @default(now()) @map(name: "updated_at")
-
- @@map(name: "verification_requests")
-}
-
model OAuthToken {
id Int @id @default(autoincrement())
userId String @map(name: "user_id")
@@ -49,7 +7,7 @@ model OAuthToken {
updatedAt DateTime @default(now()) @map(name: "updated_at")
// relations:
- user User @relation(fields: [userId], references: [id]) // Beziehung zu User
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade) // Beziehung zu User
@@map(name: "oauth_tokens")
}
diff --git a/packages/database/prisma/schema/chatMessage.prisma b/packages/database/prisma/schema/chatMessage.prisma
index 57faf593..48049fe7 100644
--- a/packages/database/prisma/schema/chatMessage.prisma
+++ b/packages/database/prisma/schema/chatMessage.prisma
@@ -8,6 +8,6 @@ model ChatMessage {
senderName String
// relations:
- sender User @relation("SentMessages", fields: [senderId], references: [id])
- receiver User @relation("ReceivedMessages", fields: [receiverId], references: [id])
+ sender User @relation("SentMessages", fields: [senderId], references: [id], onDelete: Cascade)
+ receiver User @relation("ReceivedMessages", fields: [receiverId], references: [id], onDelete: Cascade)
}
diff --git a/packages/database/prisma/schema/connectedAircraft.prisma b/packages/database/prisma/schema/connectedAircraft.prisma
index d310e13c..faf3168f 100644
--- a/packages/database/prisma/schema/connectedAircraft.prisma
+++ b/packages/database/prisma/schema/connectedAircraft.prisma
@@ -19,6 +19,6 @@ model ConnectedAircraft {
positionLogIds Int[] @default([])
// relations:
- User User @relation(fields: [userId], references: [id])
- Station Station @relation(fields: [stationId], references: [id])
+ User User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ Station Station @relation(fields: [stationId], references: [id], onDelete: Cascade)
}
diff --git a/packages/database/prisma/schema/connectedDispatcher.prisma b/packages/database/prisma/schema/connectedDispatcher.prisma
index a689188c..3879f5fe 100644
--- a/packages/database/prisma/schema/connectedDispatcher.prisma
+++ b/packages/database/prisma/schema/connectedDispatcher.prisma
@@ -9,5 +9,5 @@ model ConnectedDispatcher {
logoutTime DateTime?
// relations:
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
diff --git a/packages/database/prisma/schema/event.prisma b/packages/database/prisma/schema/event.prisma
index 0162de2f..2262d6a7 100644
--- a/packages/database/prisma/schema/event.prisma
+++ b/packages/database/prisma/schema/event.prisma
@@ -28,7 +28,7 @@ model Participant {
statusLog Json[] @default([])
eventId Int
// relations:
- User User @relation(fields: [userId], references: [id])
+ User User @relation(fields: [userId], references: [id], onDelete: Cascade)
Event Event @relation(fields: [eventId], references: [id])
EventAppointment EventAppointment? @relation(fields: [eventAppointmentId], references: [id])
}
diff --git a/packages/database/prisma/schema/mission.prisma b/packages/database/prisma/schema/mission.prisma
index d149cd40..9ee886e6 100644
--- a/packages/database/prisma/schema/mission.prisma
+++ b/packages/database/prisma/schema/mission.prisma
@@ -29,11 +29,11 @@ model Mission {
hpgValidationState HpgValidationState @default(NOT_VALIDATED)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
- createdUserId String
+ createdUserId String?
// relations:
- CreatedUser User @relation(fields: [createdUserId], references: [id])
+ CreatedUser User? @relation(fields: [createdUserId], references: [id])
MissionsOnStations MissionsOnStations[]
MissionOnStationUsers MissionOnStationUsers[]
diff --git a/packages/database/prisma/schema/penalty.prisma b/packages/database/prisma/schema/penalty.prisma
index aa581e96..27a163f4 100644
--- a/packages/database/prisma/schema/penalty.prisma
+++ b/packages/database/prisma/schema/penalty.prisma
@@ -1,7 +1,7 @@
model Penalty {
- id Int @id @default(autoincrement())
+ id Int @id @default(autoincrement())
userId String
- createdUserId String
+ createdUserId String?
reportId Int?
type PenaltyType
@@ -13,8 +13,8 @@ model Penalty {
timestamp DateTime @default(now())
// relations:
- User User @relation(fields: [userId], references: [id])
- CreatedUser User @relation("CreatedPenalties", fields: [createdUserId], references: [id])
+ User User @relation(fields: [userId], references: [id], onDelete: Cascade)
+ CreatedUser User? @relation("CreatedPenalties", fields: [createdUserId], references: [id])
Report Report? @relation(fields: [reportId], references: [id])
}
diff --git a/packages/database/prisma/schema/positionLog.prisma b/packages/database/prisma/schema/positionLog.prisma
index 43d04f94..2f2df182 100644
--- a/packages/database/prisma/schema/positionLog.prisma
+++ b/packages/database/prisma/schema/positionLog.prisma
@@ -9,5 +9,5 @@ model PositionLog {
heading Int
timestamp DateTime @default(now())
// relations:
- user User @relation(fields: [userId], references: [id])
+ user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
diff --git a/packages/database/prisma/schema/report.prisma b/packages/database/prisma/schema/report.prisma
index 2eb850ab..7bcd0bdd 100644
--- a/packages/database/prisma/schema/report.prisma
+++ b/packages/database/prisma/schema/report.prisma
@@ -1,7 +1,7 @@
model Report {
id Int @id @default(autoincrement())
text String
- senderUserId String
+ senderUserId String?
reportedUserRole String @default("KP")
reportedUserId String
timestamp DateTime @default(now())
@@ -10,8 +10,8 @@ model Report {
reviewerUserId String?
// relations:
- Sender User @relation("SentReports", fields: [senderUserId], references: [id])
- Reported User @relation("ReceivedReports", fields: [reportedUserId], references: [id])
+ Sender User? @relation("SentReports", fields: [senderUserId], references: [id])
+ Reported User @relation("ReceivedReports", fields: [reportedUserId], references: [id], onDelete: Cascade)
Reviewer User? @relation("ReviewedReports", fields: [reviewerUserId], references: [id])
Penalty Penalty[]
}