Files
memegoat/backend/src/database/schemas/reports.ts
Mathis HERRIOT 38e97741e0
Some checks failed
Lint / lint (push) Failing after 4m58s
chore: reformat schemas and documentation files for consistency
Standardized formatting across database schema files and updated documentation structure to improve clarity and organization.
2026-01-05 16:17:41 +01:00

63 lines
1.7 KiB
TypeScript

import {
index,
pgEnum,
pgTable,
text,
timestamp,
uuid,
} from "drizzle-orm/pg-core";
import { contents } from "./content";
import { tags } from "./tags";
import { users } from "./users";
export const reportStatus = pgEnum("report_status", [
"pending",
"reviewed",
"resolved",
"dismissed",
]);
export const reportReason = pgEnum("report_reason", [
"inappropriate",
"spam",
"copyright",
"other",
]);
export const reports = pgTable(
"reports",
{
id: uuid("id").primaryKey().defaultRandom(),
reporterId: uuid("reporter_id")
.notNull()
.references(() => users.uuid, { onDelete: "cascade" }),
// Le signalement peut porter sur un contenu OU un tag
contentId: uuid("content_id").references(() => contents.id, {
onDelete: "cascade",
}),
tagId: uuid("tag_id").references(() => tags.id, { onDelete: "cascade" }),
reason: reportReason("reason").notNull(),
description: text("description"),
status: reportStatus("status").default("pending").notNull(),
expiresAt: timestamp("expires_at", { withTimezone: true }), // Pour purge automatique RGPD
createdAt: timestamp("created_at", { withTimezone: true })
.notNull()
.defaultNow(),
updatedAt: timestamp("updated_at", { withTimezone: true })
.notNull()
.defaultNow(),
},
(table) => ({
reporterIdx: index("reports_reporter_id_idx").on(table.reporterId),
contentIdx: index("reports_content_id_idx").on(table.contentId),
tagIdx: index("reports_tag_id_idx").on(table.tagId),
statusIdx: index("reports_status_idx").on(table.status),
expiresAtIdx: index("reports_expires_at_idx").on(table.expiresAt),
}),
);
export type ReportInDb = typeof reports.$inferSelect;
export type NewReportInDb = typeof reports.$inferInsert;