refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (5)

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 14:15:39 +02:00
1 parent 9aa4f331bf
commit 30b54e99e7
40 files changed
+1183 -784

No files matched your search

+35 -10
View File
@@ -1,3 +1,4 @@
import { and, count, eq, gte, ne } from "drizzle-orm";
import {
Ban,
Gavel,
@@ -11,8 +12,15 @@ import Link from "next/link";
import { getTranslations } from "next-intl/server";
import { StatsCard } from "@/components/admin/stats-card";
import { getMinStaffRank } from "@/lib/admin/min-staff-rank";
import {
Ban as BanTable,
db,
SupportTickets,
User,
WebsiteHelpCenterTickets,
WebsiteTicket,
} from "@/lib/db";
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
export default async function ModDashboardPage() {
const t = await getTranslations("pages.mod");
@@ -44,24 +52,41 @@ export default async function ModDashboardPage() {
const [openCfh, todayBans, modsOnline, openTickets, openHelpTickets] =
await Promise.all([
showCfh
? prisma.supportTickets.count({ where: { state: 0 } }).catch(() => 0)
? db
.select({ total: count() })
.from(SupportTickets)
.where(eq(SupportTickets.state, 0))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0)
: Promise.resolve(0),
showBans
? prisma.ban
.count({ where: { timestamp: { gte: todayStart } } })
? db
.select({ total: count() })
.from(BanTable)
.where(gte(BanTable.timestamp, todayStart))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0)
: Promise.resolve(0),
prisma.user
.count({ where: { online: "1", rank: { gte: minStaffRank } } })
db
.select({ total: count() })
.from(User)
.where(and(eq(User.online, "1"), gte(User.rank, minStaffRank)))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0),
showTickets
? prisma.websiteTicket
.count({ where: { status: { not: "closed" } } })
? db
.select({ total: count() })
.from(WebsiteTicket)
.where(ne(WebsiteTicket.status, "closed"))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0)
: Promise.resolve(0),
showTickets
? prisma.websiteHelpCenterTickets
.count({ where: { open: true } })
? db
.select({ total: count() })
.from(WebsiteHelpCenterTickets)
.where(eq(WebsiteHelpCenterTickets.open, true))
.then((rows) => rows[0]?.total ?? 0)
.catch(() => 0)
: Promise.resolve(0),
]);