checking in work

This commit is contained in:
Briant Diehl
2022-12-19 16:31:44 -07:00
parent 02b2ac5335
commit bf2bf228ae
10 changed files with 331 additions and 52 deletions
+11
View File
@@ -0,0 +1,11 @@
// Place your key bindings in this file to override the defaultsauto[]
[
{
"key": "shift+alt+ctrl+/",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"name": "region_wrap"
}
}
]
+8
View File
@@ -0,0 +1,8 @@
{
"region_wrap": {
"scope": "javascript,typescript,html,typescriptreact,javascriptreact,react",
"prefix": "region",
"body": ["$LINE_COMMENT #region [${1}]", "$TM_SELECTED_TEXT", "$LINE_COMMENT #endregion", ""],
"description": "Wrap your selected block with a region"
}
}
@@ -0,0 +1,162 @@
/*
Warnings:
- The values [SecurityConcern] on the enum `ReportReason` will be removed. If these variants are still used in the database, this will fail.
- The primary key for the `CommentReport` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `createdAt` on the `CommentReport` table. All the data in the column will be lost.
- You are about to drop the column `id` on the `CommentReport` table. All the data in the column will be lost.
- You are about to drop the column `reason` on the `CommentReport` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `CommentReport` table. All the data in the column will be lost.
- The primary key for the `ModelReport` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `createdAt` on the `ModelReport` table. All the data in the column will be lost.
- You are about to drop the column `details` on the `ModelReport` table. All the data in the column will be lost.
- You are about to drop the column `id` on the `ModelReport` table. All the data in the column will be lost.
- You are about to drop the column `reason` on the `ModelReport` table. All the data in the column will be lost.
- You are about to drop the column `reviewedAt` on the `ModelReport` table. All the data in the column will be lost.
- You are about to drop the column `status` on the `ModelReport` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `ModelReport` table. All the data in the column will be lost.
- The primary key for the `ReviewReport` table will be changed. If it partially fails, the table could be left without primary key constraint.
- You are about to drop the column `createdAt` on the `ReviewReport` table. All the data in the column will be lost.
- You are about to drop the column `id` on the `ReviewReport` table. All the data in the column will be lost.
- You are about to drop the column `reason` on the `ReviewReport` table. All the data in the column will be lost.
- You are about to drop the column `userId` on the `ReviewReport` table. All the data in the column will be lost.
- A unique constraint covering the columns `[reportId]` on the table `CommentReport` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[reportId]` on the table `ModelReport` will be added. If there are existing duplicate values, this will fail.
- A unique constraint covering the columns `[reportId]` on the table `ReviewReport` will be added. If there are existing duplicate values, this will fail.
- Added the required column `reportId` to the `CommentReport` table without a default value. This is not possible if the table is not empty.
- Added the required column `reportId` to the `ModelReport` table without a default value. This is not possible if the table is not empty.
- Added the required column `reportId` to the `ReviewReport` table without a default value. This is not possible if the table is not empty.
*/
-- AlterEnum
BEGIN;
CREATE TYPE "ReportReason_new" AS ENUM ('TOSViolation', 'NSFW', 'Ownership', 'AdminAttention', 'Claim');
ALTER TABLE "Report" ALTER COLUMN "reason" TYPE "ReportReason_new" USING ("reason"::text::"ReportReason_new");
ALTER TYPE "ReportReason" RENAME TO "ReportReason_old";
ALTER TYPE "ReportReason_new" RENAME TO "ReportReason";
DROP TYPE "ReportReason_old";
COMMIT;
-- DropForeignKey
ALTER TABLE "CommentReport" DROP CONSTRAINT "CommentReport_commentId_fkey";
-- DropForeignKey
ALTER TABLE "CommentReport" DROP CONSTRAINT "CommentReport_userId_fkey";
-- DropForeignKey
ALTER TABLE "ModelReport" DROP CONSTRAINT "ModelReport_modelId_fkey";
-- DropForeignKey
ALTER TABLE "ModelReport" DROP CONSTRAINT "ModelReport_userId_fkey";
-- DropForeignKey
ALTER TABLE "ReviewReport" DROP CONSTRAINT "ReviewReport_reviewId_fkey";
-- DropForeignKey
ALTER TABLE "ReviewReport" DROP CONSTRAINT "ReviewReport_userId_fkey";
-- CreateTable
CREATE TABLE "Report" (
"id" SERIAL NOT NULL,
"userId" INTEGER NOT NULL,
"reason" "ReportReason" NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL,
"details" JSONB,
"status" "ReportStatus" NOT NULL,
CONSTRAINT "Report_pkey" PRIMARY KEY ("id")
);
-- Comment Report
INSERT INTO "Report" ("id", "userId", "reason", "createdAt", "details", "status")
SELECT "id", "userId", "reason", "createdAt", JSONB_BUILD_OBJECT('commentId', "commentId"), 'Valid'
FROM "CommentReport";
ALTER TABLE "CommentReport" DROP CONSTRAINT "CommentReport_pkey",
DROP COLUMN "createdAt",
DROP COLUMN "id",
DROP COLUMN "reason",
DROP COLUMN "userId",
ADD COLUMN "reportId" INTEGER;
UPDATE "CommentReport" SET "reportId" = "Report"."id"
FROM "Report"
WHERE cast("Report".details->'commentId' as int) = "commentId";
ALTER TABLE "CommentReport"
ALTER COLUMN "reportId" SET NOT NULL,
ADD CONSTRAINT "CommentReport_pkey" PRIMARY KEY ("reportId", "commentId");
-- Model Report
INSERT INTO "Report" ("id", "userId", "reason", "createdAt", "details", "status")
SELECT "id", "userId", "reason", "createdAt", "details" || JSONB_BUILD_OBJECT('modelId', "modelId"), "status"
FROM "ModelReport";
ALTER TABLE "ModelReport" DROP CONSTRAINT "ModelReport_pkey",
DROP COLUMN "createdAt",
DROP COLUMN "details",
DROP COLUMN "id",
DROP COLUMN "reason",
DROP COLUMN "reviewedAt",
DROP COLUMN "status",
DROP COLUMN "userId",
ADD COLUMN "reportId" INTEGER;
UPDATE "ModelReport" SET "reportId" = "Report"."id"
FROM "Report"
WHERE cast("Report".details->'modelId' as int) = "modelId";
ALTER TABLE "ModelReport"
ALTER COLUMN "reportId" SET NOT NULL,
ADD CONSTRAINT "ModelReport_pkey" PRIMARY KEY ("reportId", "modelId");
-- Review Report
INSERT INTO "Report" ("id", "userId", "reason", "createdAt", "details", "status")
SELECT "id", "userId", "reason", "createdAt", JSONB_BUILD_OBJECT('reviewId', "reviewId"), 'Valid'
FROM "ReviewReport";
ALTER TABLE "ReviewReport" DROP CONSTRAINT "ReviewReport_pkey",
DROP COLUMN "createdAt",
DROP COLUMN "id",
DROP COLUMN "reason",
DROP COLUMN "userId",
ADD COLUMN "reportId" INTEGER,
ADD CONSTRAINT "ReviewReport_pkey" PRIMARY KEY ("reportId", "reviewId");
UPDATE "ReviewReport" SET "reportId" = "Report"."id"
FROM "Report"
WHERE cast("Report".details->'reviewId' as int) = "reviewId";
ALTER TABLE "ReviewReport"
ALTER COLUMN "reportId" SET NOT NULL,
ADD CONSTRAINT "ReviewReport_pkey" PRIMARY KEY ("reportId", "reviewId");
-- CreateIndex
CREATE UNIQUE INDEX "CommentReport_reportId_key" ON "CommentReport"("reportId");
-- CreateIndex
CREATE UNIQUE INDEX "ModelReport_reportId_key" ON "ModelReport"("reportId");
-- CreateIndex
CREATE UNIQUE INDEX "ReviewReport_reportId_key" ON "ReviewReport"("reportId");
-- AddForeignKey
ALTER TABLE "Report" ADD CONSTRAINT "Report_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ModelReport" ADD CONSTRAINT "ModelReport_modelId_fkey" FOREIGN KEY ("modelId") REFERENCES "Model"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ModelReport" ADD CONSTRAINT "ModelReport_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ReviewReport" ADD CONSTRAINT "ReviewReport_reviewId_fkey" FOREIGN KEY ("reviewId") REFERENCES "Review"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "ReviewReport" ADD CONSTRAINT "ReviewReport_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "CommentReport" ADD CONSTRAINT "CommentReport_commentId_fkey" FOREIGN KEY ("commentId") REFERENCES "Comment"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
-- AddForeignKey
ALTER TABLE "CommentReport" ADD CONSTRAINT "CommentReport_reportId_fkey" FOREIGN KEY ("reportId") REFERENCES "Report"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
+44 -39
View File
@@ -3,7 +3,7 @@
generator client {
provider = "prisma-client-js"
previewFeatures = ["filteredRelationCount", "orderByNulls", "interactiveTransactions"]
previewFeatures = ["filteredRelationCount", "orderByNulls"]
}
datasource db {
@@ -63,16 +63,13 @@ model User {
models Model[]
activities UserActivity[]
saves SavedModel[]
modelReports ModelReport[]
reviewReports ReviewReport[]
Import Import[]
imports Import[]
keys ApiKey[]
favoriteModels FavoriteModel[]
links UserLink[]
rank UserRank?
comments Comment[]
commentReactions CommentReaction[]
commentReports CommentReport[]
notifications Notification[]
notificationSettings UserNotificationSettings[]
webhooks Webhook[]
@@ -80,6 +77,7 @@ model User {
engagingUsers UserEngagement[] @relation("engagingUsers")
engagedUsers UserEngagement[] @relation("engagedUsers")
metrics UserMetric[]
reports Report[]
}
enum UserEngagementType {
@@ -364,20 +362,7 @@ enum ReportReason {
NSFW
Ownership
AdminAttention
SecurityConcern
}
model ModelReport {
id Int @id @default(autoincrement())
modelId Int
model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
reason ReportReason
createdAt DateTime @default(now())
details Json?
status ReportStatus
reviewedAt DateTime?
Claim
}
enum ReportStatus {
@@ -386,6 +371,46 @@ enum ReportStatus {
Invalid
}
model Report {
id Int @id @default(autoincrement())
userId Int
user User @relation(fields: [userId], references: [id])
reason ReportReason
createdAt DateTime
details Json?
status ReportStatus
model ModelReport?
review ReviewReport?
comment CommentReport?
}
model ModelReport {
modelId Int
model Model @relation(fields: [modelId], references: [id])
reportId Int @unique
report Report @relation(fields: [reportId], references: [id])
@@id([reportId, modelId])
}
model ReviewReport {
reviewId Int
review Review @relation(fields: [reviewId], references: [id])
reportId Int @unique
report Report @relation(fields: [reportId], references: [id])
@@id([reportId, reviewId])
}
model CommentReport {
commentId Int
comment Comment @relation(fields: [commentId], references: [id])
reportId Int @unique
report Report @relation(fields: [reportId], references: [id])
@@id([reportId, commentId])
}
model Review {
id Int @id @default(autoincrement())
model Model @relation(fields: [modelId], references: [id], onDelete: Cascade)
@@ -407,16 +432,6 @@ model Review {
comments Comment[]
}
model ReviewReport {
id Int @id @default(autoincrement())
reviewId Int
review Review @relation(fields: [reviewId], references: [id], onDelete: Cascade)
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
reason ReportReason
createdAt DateTime @default(now())
}
enum ReviewReactions {
Like
Dislike
@@ -601,16 +616,6 @@ model CommentReaction {
@@unique([commentId, userId, reaction])
}
model CommentReport {
id Int @id @default(autoincrement())
commentId Int
comment Comment @relation(fields: [commentId], references: [id], onDelete: Cascade)
userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
reason ReportReason
createdAt DateTime @default(now())
}
model Log {
id String @id @default(cuid())
event String
View File
+58
View File
@@ -0,0 +1,58 @@
import { Stack, Group, Button } from '@mantine/core';
import { z } from 'zod';
import { Form, InputTextArea, useForm } from '~/libs/form';
import { reportNsfwDetailsSchema } from '~/server/schema/report.schema';
export const NsfwForm = ({
onSubmit,
}: {
onSubmit: (values: z.infer<typeof reportNsfwDetailsSchema>) => void;
}) => {
const form = useForm({
schema: reportNsfwDetailsSchema,
shouldUnregister: false,
});
return (
<Form form={form} onSubmit={onSubmit}>
<InputTextArea name="comment" label="Comment" />
</Form>
);
};
export const createReportForm = <TSchema extends z.AnyZodObject>({
schema,
}: {
schema: TSchema;
}) => {
function ReportForm({
onSubmit,
onCancel,
disabled,
}: {
onSubmit: (values: z.infer<TSchema>) => void;
onCancel: () => void;
disabled?: boolean;
}) {
const form = useForm({
schema,
shouldUnregister: false,
});
return (
<Form form={form} onSubmit={onSubmit}>
<Stack>
<Group grow>
<Button onClick={onCancel} variant="default">
Cancel
</Button>
<Button type="submit" disabled={disabled}>
Submit
</Button>
</Group>
</Stack>
</Form>
);
}
return ReportForm;
};
+48 -13
View File
@@ -1,38 +1,73 @@
import { ReportReason, ReportStatus } from '@prisma/client';
import { z } from 'zod';
const baseSchema = z.object({ id: z.number() });
// #region [report reason detail schemas]
const baseDetailSchema = z.object({ comment: z.string().optional() });
export const reportNsfwSchema = baseSchema.extend({
reason: z.literal(ReportReason.NSFW),
status: z.nativeEnum(ReportStatus).default(ReportStatus.Valid),
});
export const reportNsfwDetailsSchema = baseDetailSchema;
export const reportTOSViolationSchema = baseSchema.extend({
reason: z.literal(ReportReason.TOSViolation),
status: z.nativeEnum(ReportStatus).default(ReportStatus.Pending),
});
export const reportOwnershipDetailsSchema = z.object({
export const reportOwnershipDetailsSchema = baseDetailSchema.extend({
name: z.string(),
email: z.string().email(),
phone: z.string().optional(),
comment: z.string().optional(),
images: z.string().array(),
establishInterest: z.boolean().optional(),
});
export const reportTosViolationDetailsSchema = baseDetailSchema.extend({
violation: z.string().array(),
});
export const reportClaimDetailsSchema = baseDetailSchema.extend({
email: z.string().email(),
});
export const reportAdminAttentionDetailsSchema = baseDetailSchema.extend({
reason: z.string(),
});
// #endregion
// #region [report reason schemas]
const baseSchema = z.object({
id: z.number(),
details: baseDetailSchema,
});
export const reportNsfwSchema = baseSchema.extend({
reason: z.literal(ReportReason.NSFW),
status: z.nativeEnum(ReportStatus).default(ReportStatus.Valid), // TODO - remove
});
export const reportTOSViolationSchema = baseSchema.extend({
reason: z.literal(ReportReason.TOSViolation),
status: z.nativeEnum(ReportStatus).default(ReportStatus.Pending), // TODO - remove
details: reportTosViolationDetailsSchema,
});
export const reportOwnershipSchema = baseSchema.extend({
reason: z.literal(ReportReason.Ownership),
status: z.nativeEnum(ReportStatus).default(ReportStatus.Pending),
status: z.nativeEnum(ReportStatus).default(ReportStatus.Pending), // TODO - remove
details: reportOwnershipDetailsSchema,
});
export const reportClaimSchema = baseSchema.extend({
reason: z.literal(ReportReason.Claim),
details: reportClaimDetailsSchema,
});
export const reportAdminAttentionSchema = baseSchema.extend({
reason: z.literal(ReportReason.AdminAttention),
details: reportAdminAttentionDetailsSchema,
});
// #endregion
export type ModelReportInput = z.infer<typeof modelReportInputSchema>;
export const modelReportInputSchema = z.discriminatedUnion('reason', [
reportNsfwSchema,
reportTOSViolationSchema,
reportOwnershipSchema,
reportClaimSchema,
reportAdminAttentionSchema,
]);
export const reviewReportInputSchema = z.discriminatedUnion('reason', [