Skip to content

Commit bf2bf22

Browse files
committed
checking in work
1 parent 02b2ac5 commit bf2bf22

File tree

10 files changed

+331
-52
lines changed

10 files changed

+331
-52
lines changed

.vscode/keybindings.json

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Place your key bindings in this file to override the defaultsauto[]
2+
[
3+
{
4+
"key": "shift+alt+ctrl+/",
5+
"command": "editor.action.insertSnippet",
6+
"when": "editorTextFocus",
7+
"args": {
8+
"name": "region_wrap"
9+
}
10+
}
11+
]

.vscode/snippets.code-snippets

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"region_wrap": {
3+
"scope": "javascript,typescript,html,typescriptreact,javascriptreact,react",
4+
"prefix": "region",
5+
"body": ["$LINE_COMMENT #region [${1}]", "$TM_SELECTED_TEXT", "$LINE_COMMENT #endregion", ""],
6+
"description": "Wrap your selected block with a region"
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
Warnings:
3+
4+
- The values [SecurityConcern] on the enum `ReportReason` will be removed. If these variants are still used in the database, this will fail.
5+
- The primary key for the `CommentReport` table will be changed. If it partially fails, the table could be left without primary key constraint.
6+
- You are about to drop the column `createdAt` on the `CommentReport` table. All the data in the column will be lost.
7+
- You are about to drop the column `id` on the `CommentReport` table. All the data in the column will be lost.
8+
- You are about to drop the column `reason` on the `CommentReport` table. All the data in the column will be lost.
9+
- You are about to drop the column `userId` on the `CommentReport` table. All the data in the column will be lost.
10+
- The primary key for the `ModelReport` table will be changed. If it partially fails, the table could be left without primary key constraint.
11+
- You are about to drop the column `createdAt` on the `ModelReport` table. All the data in the column will be lost.
12+
- You are about to drop the column `details` on the `ModelReport` table. All the data in the column will be lost.
13+
- You are about to drop the column `id` on the `ModelReport` table. All the data in the column will be lost.
14+
- You are about to drop the column `reason` on the `ModelReport` table. All the data in the column will be lost.
15+
- You are about to drop the column `reviewedAt` on the `ModelReport` table. All the data in the column will be lost.
16+
- You are about to drop the column `status` on the `ModelReport` table. All the data in the column will be lost.
17+
- You are about to drop the column `userId` on the `ModelReport` table. All the data in the column will be lost.
18+
- The primary key for the `ReviewReport` table will be changed. If it partially fails, the table could be left without primary key constraint.
19+
- You are about to drop the column `createdAt` on the `ReviewReport` table. All the data in the column will be lost.
20+
- You are about to drop the column `id` on the `ReviewReport` table. All the data in the column will be lost.
21+
- You are about to drop the column `reason` on the `ReviewReport` table. All the data in the column will be lost.
22+
- You are about to drop the column `userId` on the `ReviewReport` table. All the data in the column will be lost.
23+
- A unique constraint covering the columns `[reportId]` on the table `CommentReport` will be added. If there are existing duplicate values, this will fail.
24+
- A unique constraint covering the columns `[reportId]` on the table `ModelReport` will be added. If there are existing duplicate values, this will fail.
25+
- A unique constraint covering the columns `[reportId]` on the table `ReviewReport` will be added. If there are existing duplicate values, this will fail.
26+
- Added the required column `reportId` to the `CommentReport` table without a default value. This is not possible if the table is not empty.
27+
- Added the required column `reportId` to the `ModelReport` table without a default value. This is not possible if the table is not empty.
28+
- Added the required column `reportId` to the `ReviewReport` table without a default value. This is not possible if the table is not empty.
29+
30+
*/
31+
-- AlterEnum
32+
BEGIN;
33+
CREATE TYPE "ReportReason_new" AS ENUM ('TOSViolation', 'NSFW', 'Ownership', 'AdminAttention', 'Claim');
34+
ALTER TABLE "Report" ALTER COLUMN "reason" TYPE "ReportReason_new" USING ("reason"::text::"ReportReason_new");
35+
ALTER TYPE "ReportReason" RENAME TO "ReportReason_old";
36+
ALTER TYPE "ReportReason_new" RENAME TO "ReportReason";
37+
DROP TYPE "ReportReason_old";
38+
COMMIT;
39+
40+
-- DropForeignKey
41+
ALTER TABLE "CommentReport" DROP CONSTRAINT "CommentReport_commentId_fkey";
42+
43+
-- DropForeignKey
44+
ALTER TABLE "CommentReport" DROP CONSTRAINT "CommentReport_userId_fkey";
45+
46+
-- DropForeignKey
47+
ALTER TABLE "ModelReport" DROP CONSTRAINT "ModelReport_modelId_fkey";
48+
49+
-- DropForeignKey
50+
ALTER TABLE "ModelReport" DROP CONSTRAINT "ModelReport_userId_fkey";
51+
52+
-- DropForeignKey
53+
ALTER TABLE "ReviewReport" DROP CONSTRAINT "ReviewReport_reviewId_fkey";
54+
55+
-- DropForeignKey
56+
ALTER TABLE "ReviewReport" DROP CONSTRAINT "ReviewReport_userId_fkey";
57+
58+
-- CreateTable
59+
CREATE TABLE "Report" (
60+
"id" SERIAL NOT NULL,
61+
"userId" INTEGER NOT NULL,
62+
"reason" "ReportReason" NOT NULL,
63+
"createdAt" TIMESTAMP(3) NOT NULL,
64+
"details" JSONB,
65+
"status" "ReportStatus" NOT NULL,
66+
67+
CONSTRAINT "Report_pkey" PRIMARY KEY ("id")
68+
);
69+
70+
-- Comment Report
71+
INSERT INTO "Report" ("id", "userId", "reason", "createdAt", "details", "status")
72+
SELECT "id", "userId", "reason", "createdAt", JSONB_BUILD_OBJECT('commentId', "commentId"), 'Valid'
73+
FROM "CommentReport";
74+
75+
ALTER TABLE "CommentReport" DROP CONSTRAINT "CommentReport_pkey",
76+
DROP COLUMN "createdAt",
77+
DROP COLUMN "id",
78+
DROP COLUMN "reason",
79+
DROP COLUMN "userId",
80+
ADD COLUMN "reportId" INTEGER;
81+
82+
UPDATE "CommentReport" SET "reportId" = "Report"."id"
83+
FROM "Report"
84+
WHERE cast("Report".details->'commentId' as int) = "commentId";
85+
86+
ALTER TABLE "CommentReport"
87+
ALTER COLUMN "reportId" SET NOT NULL,
88+
ADD CONSTRAINT "CommentReport_pkey" PRIMARY KEY ("reportId", "commentId");
89+
90+
-- Model Report
91+
INSERT INTO "Report" ("id", "userId", "reason", "createdAt", "details", "status")
92+
SELECT "id", "userId", "reason", "createdAt", "details" || JSONB_BUILD_OBJECT('modelId', "modelId"), "status"
93+
FROM "ModelReport";
94+
95+
ALTER TABLE "ModelReport" DROP CONSTRAINT "ModelReport_pkey",
96+
DROP COLUMN "createdAt",
97+
DROP COLUMN "details",
98+
DROP COLUMN "id",
99+
DROP COLUMN "reason",
100+
DROP COLUMN "reviewedAt",
101+
DROP COLUMN "status",
102+
DROP COLUMN "userId",
103+
ADD COLUMN "reportId" INTEGER;
104+
105+
UPDATE "ModelReport" SET "reportId" = "Report"."id"
106+
FROM "Report"
107+
WHERE cast("Report".details->'modelId' as int) = "modelId";
108+
109+
ALTER TABLE "ModelReport"
110+
ALTER COLUMN "reportId" SET NOT NULL,
111+
ADD CONSTRAINT "ModelReport_pkey" PRIMARY KEY ("reportId", "modelId");
112+
113+
-- Review Report
114+
INSERT INTO "Report" ("id", "userId", "reason", "createdAt", "details", "status")
115+
SELECT "id", "userId", "reason", "createdAt", JSONB_BUILD_OBJECT('reviewId', "reviewId"), 'Valid'
116+
FROM "ReviewReport";
117+
118+
ALTER TABLE "ReviewReport" DROP CONSTRAINT "ReviewReport_pkey",
119+
DROP COLUMN "createdAt",
120+
DROP COLUMN "id",
121+
DROP COLUMN "reason",
122+
DROP COLUMN "userId",
123+
ADD COLUMN "reportId" INTEGER,
124+
ADD CONSTRAINT "ReviewReport_pkey" PRIMARY KEY ("reportId", "reviewId");
125+
126+
UPDATE "ReviewReport" SET "reportId" = "Report"."id"
127+
FROM "Report"
128+
WHERE cast("Report".details->'reviewId' as int) = "reviewId";
129+
130+
ALTER TABLE "ReviewReport"
131+
ALTER COLUMN "reportId" SET NOT NULL,
132+
ADD CONSTRAINT "ReviewReport_pkey" PRIMARY KEY ("reportId", "reviewId");
133+
134+
-- CreateIndex
135+
CREATE UNIQUE INDEX "CommentReport_reportId_key" ON "CommentReport"("reportId");
136+
137+
-- CreateIndex
138+
CREATE UNIQUE INDEX "ModelReport_reportId_key" ON "ModelReport"("reportId");
139+
140+
-- CreateIndex
141+
CREATE UNIQUE INDEX "ReviewReport_reportId_key" ON "ReviewReport"("reportId");
142+
143+
-- AddForeignKey
144+
ALTER TABLE "Report" ADD CONSTRAINT "Report_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
145+
146+
-- AddForeignKey
147+
ALTER TABLE "ModelReport" ADD CONSTRAINT "ModelReport_modelId_fkey" FOREIGN KEY ("modelId") REFERENCES "Model"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
148+
149+
-- AddForeignKey
150+
ALTER TABLE "ModelReport" ADD CONSTRAINT "ModelReport_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
151+
152+
-- AddForeignKey
153+
ALTER TABLE "ReviewReport" ADD CONSTRAINT "ReviewReport_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
154+
155+
-- AddForeignKey
156+
ALTER TABLE "ReviewReport" ADD CONSTRAINT "ReviewReport_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
157+
158+
-- AddForeignKey
159+
ALTER TABLE "CommentReport" ADD CONSTRAINT "CommentReport_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "Comment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
160+
161+
-- AddForeignKey
162+
ALTER TABLE "CommentReport" ADD CONSTRAINT "CommentReport_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

prisma/schema.prisma

+44-39
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
generator client {
55
provider = "prisma-client-js"
6-
previewFeatures = ["filteredRelationCount", "orderByNulls", "interactiveTransactions"]
6+
previewFeatures = ["filteredRelationCount", "orderByNulls"]
77
}
88

99
datasource db {
@@ -63,23 +63,21 @@ model User {
6363
models Model[]
6464
activities UserActivity[]
6565
saves SavedModel[]
66-
modelReports ModelReport[]
67-
reviewReports ReviewReport[]
68-
Import Import[]
66+
imports Import[]
6967
keys ApiKey[]
7068
favoriteModels FavoriteModel[]
7169
links UserLink[]
7270
rank UserRank?
7371
comments Comment[]
7472
commentReactions CommentReaction[]
75-
commentReports CommentReport[]
7673
notifications Notification[]
7774
notificationSettings UserNotificationSettings[]
7875
webhooks Webhook[]
7976
interests ModelInterest[]
8077
engagingUsers UserEngagement[] @relation("engagingUsers")
8178
engagedUsers UserEngagement[] @relation("engagedUsers")
8279
metrics UserMetric[]
80+
reports Report[]
8381
}
8482

8583
enum UserEngagementType {
@@ -364,20 +362,7 @@ enum ReportReason {
364362
NSFW
365363
Ownership
366364
AdminAttention
367-
SecurityConcern
368-
}
369-
370-
model ModelReport {
371-
id Int @id @default(autoincrement())
372-
modelId Int
373-
model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
374-
userId Int
375-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
376-
reason ReportReason
377-
createdAt DateTime @default(now())
378-
details Json?
379-
status ReportStatus
380-
reviewedAt DateTime?
365+
Claim
381366
}
382367

383368
enum ReportStatus {
@@ -386,6 +371,46 @@ enum ReportStatus {
386371
Invalid
387372
}
388373

374+
model Report {
375+
id Int @id @default(autoincrement())
376+
userId Int
377+
user User @relation(fields: [userId], references: [id])
378+
reason ReportReason
379+
createdAt DateTime
380+
details Json?
381+
status ReportStatus
382+
model ModelReport?
383+
review ReviewReport?
384+
comment CommentReport?
385+
}
386+
387+
model ModelReport {
388+
modelId Int
389+
model Model @relation(fields: [modelId], references: [id])
390+
reportId Int @unique
391+
report Report @relation(fields: [reportId], references: [id])
392+
393+
@@id([reportId, modelId])
394+
}
395+
396+
model ReviewReport {
397+
reviewId Int
398+
review Review @relation(fields: [reviewId], references: [id])
399+
reportId Int @unique
400+
report Report @relation(fields: [reportId], references: [id])
401+
402+
@@id([reportId, reviewId])
403+
}
404+
405+
model CommentReport {
406+
commentId Int
407+
comment Comment @relation(fields: [commentId], references: [id])
408+
reportId Int @unique
409+
report Report @relation(fields: [reportId], references: [id])
410+
411+
@@id([reportId, commentId])
412+
}
413+
389414
model Review {
390415
id Int @id @default(autoincrement())
391416
model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
@@ -407,16 +432,6 @@ model Review {
407432
comments Comment[]
408433
}
409434

410-
model ReviewReport {
411-
id Int @id @default(autoincrement())
412-
reviewId Int
413-
review Review @relation(fields: [reviewId], references: [id], onDelete: Cascade)
414-
userId Int
415-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
416-
reason ReportReason
417-
createdAt DateTime @default(now())
418-
}
419-
420435
enum ReviewReactions {
421436
Like
422437
Dislike
@@ -601,16 +616,6 @@ model CommentReaction {
601616
@@unique([commentId, userId, reaction])
602617
}
603618

604-
model CommentReport {
605-
id Int @id @default(autoincrement())
606-
commentId Int
607-
comment Comment @relation(fields: [commentId], references: [id], onDelete: Cascade)
608-
userId Int
609-
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
610-
reason ReportReason
611-
createdAt DateTime @default(now())
612-
}
613-
614619
model Log {
615620
id String @id @default(cuid())
616621
event String

src/components/Report/AdminAttentionForm.tsx

Whitespace-only changes.

src/components/Report/ClaimForm.tsx

Whitespace-only changes.

src/components/Report/NsfwForm.tsx

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Stack, Group, Button } from '@mantine/core';
2+
import { z } from 'zod';
3+
import { Form, InputTextArea, useForm } from '~/libs/form';
4+
import { reportNsfwDetailsSchema } from '~/server/schema/report.schema';
5+
6+
export const NsfwForm = ({
7+
onSubmit,
8+
}: {
9+
onSubmit: (values: z.infer<typeof reportNsfwDetailsSchema>) => void;
10+
}) => {
11+
const form = useForm({
12+
schema: reportNsfwDetailsSchema,
13+
shouldUnregister: false,
14+
});
15+
16+
return (
17+
<Form form={form} onSubmit={onSubmit}>
18+
<InputTextArea name="comment" label="Comment" />
19+
</Form>
20+
);
21+
};
22+
23+
export const createReportForm = <TSchema extends z.AnyZodObject>({
24+
schema,
25+
}: {
26+
schema: TSchema;
27+
}) => {
28+
function ReportForm({
29+
onSubmit,
30+
onCancel,
31+
disabled,
32+
}: {
33+
onSubmit: (values: z.infer<TSchema>) => void;
34+
onCancel: () => void;
35+
disabled?: boolean;
36+
}) {
37+
const form = useForm({
38+
schema,
39+
shouldUnregister: false,
40+
});
41+
42+
return (
43+
<Form form={form} onSubmit={onSubmit}>
44+
<Stack>
45+
<Group grow>
46+
<Button onClick={onCancel} variant="default">
47+
Cancel
48+
</Button>
49+
<Button type="submit" disabled={disabled}>
50+
Submit
51+
</Button>
52+
</Group>
53+
</Stack>
54+
</Form>
55+
);
56+
}
57+
return ReportForm;
58+
};

src/components/Report/OwnershipForm.tsx

Whitespace-only changes.

src/components/Report/TosViolationForm.tsx

Whitespace-only changes.

0 commit comments

Comments
 (0)