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

Co-authored-by: Cursor <[email protected]>
This commit is contained in:
SimoandCursor committed 2026-08-01 14:15:36 +02:00
1 parent 580972c0a0
commit 9aa4f331bf
40 files changed
+1259 -927

No files matched your search

+15 -14
View File
@@ -1,6 +1,7 @@
import { desc } from "drizzle-orm";
import { redirect } from "next/navigation";
import { db, WebsiteShopVouchers } from "@/lib/db";
import { canAccess, getAdminContext, PERMS } from "@/lib/permissions";
import { prisma } from "@/lib/prisma";
import { type VoucherRow, VouchersClient } from "./vouchers-client";
export default async function AdminVouchers() {
@@ -14,19 +15,19 @@ export default async function AdminVouchers() {
let rows: VoucherRow[] = [];
try {
const vouchers = await prisma.websiteShopVouchers.findMany({
select: {
id: true,
code: true,
amount: true,
maxUses: true,
useCount: true,
expiresAt: true,
createdAt: true,
},
orderBy: { id: "desc" },
take: 200,
});
const vouchers = await db
.select({
id: WebsiteShopVouchers.id,
code: WebsiteShopVouchers.code,
amount: WebsiteShopVouchers.amount,
maxUses: WebsiteShopVouchers.maxUses,
useCount: WebsiteShopVouchers.useCount,
expiresAt: WebsiteShopVouchers.expiresAt,
createdAt: WebsiteShopVouchers.createdAt,
})
.from(WebsiteShopVouchers)
.orderBy(desc(WebsiteShopVouchers.id))
.limit(200);
rows = vouchers.map((v) => {
const expired = v.expiresAt ? v.expiresAt.getTime() <= now : false;
const usedUp = v.maxUses > 0 && v.useCount >= v.maxUses;