added user casacde delete

This commit is contained in:
PxlLoewe
2025-06-25 17:09:41 -07:00
parent e17350596f
commit 577a18d595
14 changed files with 47 additions and 94 deletions

20
.vscode/settings.json vendored
View File

@@ -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"
}
]
}
}

View File

@@ -47,10 +47,12 @@ export const Penalty = async () => {
<p className="text-left">
<span className="font-bold">Grund:</span> {openTimeban[0].reason}
</p>
<p className="text-left">
<span className="font-bold">Admin:</span>{" "}
{getPublicUser(openTimeban[0].CreatedUser).fullName}
</p>
{openTimeban[0].CreatedUser && (
<p className="text-left">
<span className="font-bold">Admin:</span>{" "}
{getPublicUser(openTimeban[0].CreatedUser).fullName}
</p>
)}
</div>
)}
{session?.user.isBanned && (
@@ -68,10 +70,12 @@ export const Penalty = async () => {
<p className="text-left font-bold">
Grund: {openBans[0].reason || "Keine Begründung gefunden"}
</p>
<p className="text-left">
<span className="font-bold">Admin:</span>{" "}
{getPublicUser(openBans[0].CreatedUser).fullName || "Keine Admin gefunden"}
</p>
{openBans[0].CreatedUser && (
<p className="text-left">
<span className="font-bold">Admin:</span>{" "}
{getPublicUser(openBans[0].CreatedUser).fullName}
</p>
)}
</>
)}
</div>

View File

@@ -43,10 +43,12 @@ export default async function Page({ params }: { params: Promise<{ id: string }>
<span className="font-semibold">Benutzer:</span> {penalty.User.firstname}{" "}
{penalty.User.lastname} ({penalty.User.publicId})
</p>
<p>
<span className="font-semibold">Erstellt von:</span> {penalty.CreatedUser.firstname}{" "}
{penalty.CreatedUser.lastname} ({penalty.CreatedUser.publicId})
</p>
{penalty.CreatedUser && (
<p>
<span className="font-semibold">Erstellt von:</span> {penalty.CreatedUser.firstname}{" "}
{penalty.CreatedUser.lastname} ({penalty.CreatedUser.publicId})
</p>
)}
<p>
<span className="font-semibold">Typ:</span> {penalty.type}
</p>

View File

@@ -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<Penalty & { Report: Report }>[] = [
export const penaltyColumns: ColumnDef<Penalty & { Report: Report; CreatedUser: User | null }>[] = [
{
accessorKey: "type",
header: "Typ",
@@ -59,7 +59,8 @@ export const penaltyColumns: ColumnDef<Penalty & { Report: Report }>[] = [
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})`;
},
},

View File

@@ -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;
};
}) => {

View File

@@ -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")
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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)
}

View File

@@ -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])
}

View File

@@ -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[]

View File

@@ -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])
}

View File

@@ -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)
}

View File

@@ -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[]
}