refactor(db): migrate app pages and APIs from Prisma facade to Drizzle (4)
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
580972c0a0
commit
9aa4f331bf
40 files changed
+1259
-927
No files matched your search
@@ -1,7 +1,8 @@
|
||||
import { eq, sql } from "drizzle-orm";
|
||||
import { NextResponse } from "next/server";
|
||||
import { withAdmin } from "@/lib/api-handler";
|
||||
import { db, User } from "@/lib/db";
|
||||
import { PERMS } from "@/lib/permissions";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { rcon } from "@/lib/services/rcon";
|
||||
import { logStaffActivity } from "@/lib/services/staff-activity";
|
||||
|
||||
@@ -31,9 +32,14 @@ export const POST = withAdmin(
|
||||
);
|
||||
}
|
||||
|
||||
const rankExists = await prisma.$queryRaw<{ id: number }[]>`
|
||||
SELECT id FROM permission_ranks WHERE id = ${rank} LIMIT 1
|
||||
`.catch(() => [] as { id: number }[]);
|
||||
const [rankExists] = (await db
|
||||
.execute(
|
||||
sql`SELECT id FROM permission_ranks WHERE id = ${rank} LIMIT 1`,
|
||||
)
|
||||
.catch(() => [[]] as unknown as [unknown[], unknown])) as unknown as [
|
||||
{ id: number }[],
|
||||
unknown,
|
||||
];
|
||||
if (rankExists.length === 0) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Rank does not exist" },
|
||||
@@ -41,10 +47,11 @@ export const POST = withAdmin(
|
||||
);
|
||||
}
|
||||
|
||||
const target = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
select: { rank: true },
|
||||
});
|
||||
const [target] = await db
|
||||
.select({ rank: User.rank })
|
||||
.from(User)
|
||||
.where(eq(User.id, userId))
|
||||
.limit(1);
|
||||
if (!target) {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "User not found" },
|
||||
@@ -74,7 +81,7 @@ export const POST = withAdmin(
|
||||
}
|
||||
}
|
||||
|
||||
await prisma.user.update({ where: { id: userId }, data: { rank } });
|
||||
await db.update(User).set({ rank }).where(eq(User.id, userId));
|
||||
await rcon.setRank(userId, rank);
|
||||
await logStaffActivity({
|
||||
staffId,
|
||||
|
||||
Reference in new issue
Block a user