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

+30 -23
View File
@@ -1,8 +1,9 @@
// Public REST: rare furni trade values (website_rare_values).
// AtomCMS JSON API parity — read-only catalog of rares with their credit /
// currency values. Supports ?category=<id> filter; paginated, ordered by name.
import { asc, count, eq } from "drizzle-orm";
import { apiError, apiJson, pagination, positiveBigInt } from "@/lib/api";
import { prisma } from "@/lib/prisma";
import { db, WebsiteRareValues } from "@/lib/db";
export const dynamic = "force-dynamic";
@@ -12,33 +13,39 @@ export async function GET(req: Request) {
// Optional ?category=<id> filter (category_id is a BigInt).
const categoryRaw = sp.get("category");
let where: { categoryId?: bigint } = {};
let categoryId: bigint | undefined;
if (categoryRaw !== null) {
const categoryId = positiveBigInt(categoryRaw);
if (!categoryId) return apiError("A valid category id is required", 422);
where = { categoryId };
const parsed = positiveBigInt(categoryRaw);
if (!parsed) return apiError("A valid category id is required", 422);
categoryId = parsed;
}
try {
const [total, data] = await Promise.all([
prisma.websiteRareValues.count({ where }),
prisma.websiteRareValues.findMany({
where,
orderBy: { name: "asc" },
skip,
take,
select: {
id: true,
categoryId: true,
itemId: true,
name: true,
creditValue: true,
currencyValue: true,
currencyType: true,
furnitureIcon: true,
},
}),
const where =
categoryId !== undefined
? eq(WebsiteRareValues.categoryId, categoryId)
: undefined;
const [totalRows, data] = await Promise.all([
db.select({ total: count() }).from(WebsiteRareValues).where(where),
db
.select({
id: WebsiteRareValues.id,
categoryId: WebsiteRareValues.categoryId,
itemId: WebsiteRareValues.itemId,
name: WebsiteRareValues.name,
creditValue: WebsiteRareValues.creditValue,
currencyValue: WebsiteRareValues.currencyValue,
currencyType: WebsiteRareValues.currencyType,
furnitureIcon: WebsiteRareValues.furnitureIcon,
})
.from(WebsiteRareValues)
.where(where)
.orderBy(asc(WebsiteRareValues.name))
.limit(take)
.offset(skip),
]);
const total = totalRows[0]?.total ?? 0;
return apiJson({
data,