feat: user lookup and user punishments in admin panel

need to work on actually punishing the user
This commit is contained in:
trafficlunar 2025-05-25 22:16:41 +01:00
parent 0c7be71b2c
commit e195d2e80b
7 changed files with 534 additions and 7 deletions

View file

@ -0,0 +1,36 @@
-- CreateEnum
CREATE TYPE "PunishmentType" AS ENUM ('WARNING', 'TEMP_EXILE', 'PERM_EXILE');
-- AlterTable
ALTER TABLE "miis" ADD COLUMN "punishmentId" INTEGER;
-- CreateTable
CREATE TABLE "mii_punishments" (
"punishmentId" INTEGER NOT NULL,
"miiId" INTEGER NOT NULL,
"reason" TEXT NOT NULL,
CONSTRAINT "mii_punishments_pkey" PRIMARY KEY ("punishmentId","miiId")
);
-- CreateTable
CREATE TABLE "punishments" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"type" "PunishmentType" NOT NULL,
"notes" TEXT NOT NULL,
"reasons" TEXT[],
"expiresAt" TIMESTAMP(3),
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT "punishments_pkey" PRIMARY KEY ("id")
);
-- AddForeignKey
ALTER TABLE "mii_punishments" ADD CONSTRAINT "mii_punishments_punishmentId_fkey" FOREIGN KEY ("punishmentId") REFERENCES "punishments"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "mii_punishments" ADD CONSTRAINT "mii_punishments_miiId_fkey" FOREIGN KEY ("miiId") REFERENCES "miis"("id") ON DELETE CASCADE ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "punishments" ADD CONSTRAINT "punishments_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

View file

@ -21,12 +21,14 @@ model User {
usernameUpdatedAt DateTime?
imageUpdatedAt DateTime?
accounts Account[]
sessions Session[]
miis Mii[]
likes Like[]
reportsAuthored Report[] @relation("ReportAuthor")
reports Report[] @relation("ReportTargetCreator")
accounts Account[]
sessions Session[]
miis Mii[]
likes Like[]
reportsAuthored Report[] @relation("ReportAuthor")
reports Report[] @relation("ReportTargetCreator")
punishments Punishment[]
@@map("users")
}
@ -84,6 +86,9 @@ model Mii {
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
likedBy Like[]
punishmentId Int?
punishments MiiPunishment[]
@@map("miis")
}
@ -118,6 +123,35 @@ model Report {
@@map("reports")
}
model MiiPunishment {
punishmentId Int
miiId Int
reason String
punishment Punishment @relation(fields: [punishmentId], references: [id], onDelete: Cascade)
mii Mii @relation(fields: [miiId], references: [id], onDelete: Cascade)
@@id([punishmentId, miiId])
@@map("mii_punishments")
}
model Punishment {
id Int @id @default(autoincrement())
userId Int
type PunishmentType
notes String
reasons String[]
violatingMiis MiiPunishment[]
expiresAt DateTime?
createdAt DateTime @default(now())
user User @relation(fields: [userId], references: [id])
@@map("punishments")
}
enum MiiGender {
MALE
FEMALE
@ -140,3 +174,9 @@ enum ReportStatus {
RESOLVED
DISMISSED
}
enum PunishmentType {
WARNING
TEMP_EXILE
PERM_EXILE
}