refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (5)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
9aa4f331bf
commit
30b54e99e7
40 files changed
+1183
-784
No files matched your search
@@ -1,8 +1,9 @@
|
||||
import { count, desc, eq, inArray } from "drizzle-orm";
|
||||
import { notFound } from "next/navigation";
|
||||
import { CfhDetail } from "@/app/admin/moderation/cfh/[id]/cfh-detail";
|
||||
import { requireModPermission } from "@/lib/admin/guard";
|
||||
import { Ban, db, SupportTickets, User } from "@/lib/db";
|
||||
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export default async function ModCfhDetailPage({
|
||||
params,
|
||||
@@ -16,9 +17,11 @@ export default async function ModCfhDetailPage({
|
||||
const ticketId = Number(id);
|
||||
if (Number.isNaN(ticketId)) notFound();
|
||||
|
||||
const ticket = await prisma.supportTickets.findUnique({
|
||||
where: { id: ticketId },
|
||||
});
|
||||
const [ticket] = await db
|
||||
.select()
|
||||
.from(SupportTickets)
|
||||
.where(eq(SupportTickets.id, ticketId))
|
||||
.limit(1);
|
||||
if (!ticket) notFound();
|
||||
|
||||
const canEdit =
|
||||
@@ -30,32 +33,49 @@ export default async function ModCfhDetailPage({
|
||||
);
|
||||
const users =
|
||||
userIds.length > 0
|
||||
? await prisma.user.findMany({
|
||||
where: { id: { in: userIds } },
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
look: true,
|
||||
rank: true,
|
||||
online: true,
|
||||
ipRegister: true,
|
||||
mail: true,
|
||||
},
|
||||
})
|
||||
? await db
|
||||
.select({
|
||||
id: User.id,
|
||||
username: User.username,
|
||||
look: User.look,
|
||||
rank: User.rank,
|
||||
online: User.online,
|
||||
ipRegister: User.ipRegister,
|
||||
mail: User.mail,
|
||||
})
|
||||
.from(User)
|
||||
.where(inArray(User.id, userIds))
|
||||
: [];
|
||||
const userMap = Object.fromEntries(users.map((u) => [u.id, u]));
|
||||
|
||||
const reportedId = ticket.reportedId;
|
||||
const [banCount, recentBans] = reportedId
|
||||
? await Promise.all([
|
||||
prisma.ban.count({ where: { userId: reportedId } }),
|
||||
prisma.ban.findMany({
|
||||
where: { userId: reportedId },
|
||||
orderBy: { id: "desc" },
|
||||
take: 5,
|
||||
}),
|
||||
])
|
||||
: [0, []];
|
||||
let banCount = 0;
|
||||
let recentBans: {
|
||||
id: number;
|
||||
banReason: string;
|
||||
type: string;
|
||||
userStaffId: number;
|
||||
timestamp: number;
|
||||
}[] = [];
|
||||
if (reportedId) {
|
||||
const [countRows, bans] = await Promise.all([
|
||||
db.select({ total: count() }).from(Ban).where(eq(Ban.userId, reportedId)),
|
||||
db
|
||||
.select({
|
||||
id: Ban.id,
|
||||
banReason: Ban.banReason,
|
||||
type: Ban.type,
|
||||
userStaffId: Ban.userStaffId,
|
||||
timestamp: Ban.timestamp,
|
||||
})
|
||||
.from(Ban)
|
||||
.where(eq(Ban.userId, reportedId))
|
||||
.orderBy(desc(Ban.id))
|
||||
.limit(5),
|
||||
]);
|
||||
banCount = countRows[0]?.total ?? 0;
|
||||
recentBans = bans;
|
||||
}
|
||||
|
||||
return (
|
||||
<CfhDetail
|
||||
|
||||
Reference in new issue
Block a user