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

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 14:15:12 +02:00
1 parent 53b350057d
commit 7c39aef5d9
40 files changed
+1124 -692

No files matched your search

+17 -10
View File
@@ -1,8 +1,9 @@
import { desc, eq } from "drizzle-orm";
import { redirect } from "next/navigation";
import { buyBadge } from "@/actions/draw-badge";
import { ContentCard, EmptyState, StatBlock } from "@/components/public/ui";
import { auth } from "@/lib/auth";
import { prisma } from "@/lib/prisma";
import { db, User, WebsiteDrawbadges } from "@/lib/db";
import { siteSettings } from "@/lib/services/site-settings";
// Reads the live users + website_drawbadges tables and writes credits/badges on
@@ -66,21 +67,27 @@ export default async function DrawBadgePage({
}
try {
const buyer = await prisma.user.findUnique({
where: { id: Number(session.user.id) },
select: { credits: true },
});
const [buyer] = await db
.select({ credits: User.credits })
.from(User)
.where(eq(User.id, Number(session.user.id)))
.limit(1);
credits = buyer?.credits ?? 0;
} catch {
credits = 0;
}
try {
badges = await prisma.websiteDrawbadges.findMany({
where: { published: true },
select: { id: true, badgeUrl: true, badgeName: true, badgeDesc: true },
orderBy: { id: "desc" },
});
badges = await db
.select({
id: WebsiteDrawbadges.id,
badgeUrl: WebsiteDrawbadges.badgeUrl,
badgeName: WebsiteDrawbadges.badgeName,
badgeDesc: WebsiteDrawbadges.badgeDesc,
})
.from(WebsiteDrawbadges)
.where(eq(WebsiteDrawbadges.published, true))
.orderBy(desc(WebsiteDrawbadges.id));
} catch {
badges = [];
}