refactor(db): migrate app pages and APIs from Prisma facade to Drizzle
Co-authored-by: Cursor <[email protected]>
This commit is contained in:
1 parent
53b350057d
commit
7c39aef5d9
40 files changed
+1124
-692
No files matched your search
@@ -1,7 +1,13 @@
|
||||
import { asc } from "drizzle-orm";
|
||||
import Link from "next/link";
|
||||
import { getTranslations } from "next-intl/server";
|
||||
import { ContentCard, EmptyState } from "@/components/public/ui";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import {
|
||||
db,
|
||||
WebsiteHelpCenterCategories,
|
||||
WebsiteRuleCategories,
|
||||
WebsiteRules,
|
||||
} from "@/lib/db";
|
||||
|
||||
export const revalidate = 300;
|
||||
|
||||
@@ -40,40 +46,57 @@ export default async function HelpCenterPage() {
|
||||
|
||||
let categories: HelpCategory[] = [];
|
||||
try {
|
||||
categories = await prisma.websiteHelpCenterCategories.findMany({
|
||||
orderBy: [{ position: "asc" }, { id: "asc" }],
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
content: true,
|
||||
imageUrl: true,
|
||||
buttonText: true,
|
||||
buttonUrl: true,
|
||||
buttonColor: true,
|
||||
buttonBorderColor: true,
|
||||
smallBox: true,
|
||||
},
|
||||
});
|
||||
categories = await db
|
||||
.select({
|
||||
id: WebsiteHelpCenterCategories.id,
|
||||
name: WebsiteHelpCenterCategories.name,
|
||||
content: WebsiteHelpCenterCategories.content,
|
||||
imageUrl: WebsiteHelpCenterCategories.imageUrl,
|
||||
buttonText: WebsiteHelpCenterCategories.buttonText,
|
||||
buttonUrl: WebsiteHelpCenterCategories.buttonUrl,
|
||||
buttonColor: WebsiteHelpCenterCategories.buttonColor,
|
||||
buttonBorderColor: WebsiteHelpCenterCategories.buttonBorderColor,
|
||||
smallBox: WebsiteHelpCenterCategories.smallBox,
|
||||
})
|
||||
.from(WebsiteHelpCenterCategories)
|
||||
.orderBy(
|
||||
asc(WebsiteHelpCenterCategories.position),
|
||||
asc(WebsiteHelpCenterCategories.id),
|
||||
);
|
||||
} catch {
|
||||
// DB unavailable — render the shell without help categories.
|
||||
}
|
||||
|
||||
let ruleCategories: RuleCategory[] = [];
|
||||
try {
|
||||
ruleCategories = await prisma.websiteRuleCategories.findMany({
|
||||
orderBy: { id: "asc" },
|
||||
select: { id: true, name: true, description: true, badge: true },
|
||||
});
|
||||
ruleCategories = await db
|
||||
.select({
|
||||
id: WebsiteRuleCategories.id,
|
||||
name: WebsiteRuleCategories.name,
|
||||
description: WebsiteRuleCategories.description,
|
||||
badge: WebsiteRuleCategories.badge,
|
||||
})
|
||||
.from(WebsiteRuleCategories)
|
||||
.orderBy(asc(WebsiteRuleCategories.id));
|
||||
} catch {
|
||||
// DB unavailable — render the shell without rule categories.
|
||||
}
|
||||
|
||||
let rules: Rule[] = [];
|
||||
try {
|
||||
rules = await prisma.websiteRules.findMany({
|
||||
orderBy: [{ categoryId: "asc" }, { paragraph: "asc" }, { id: "asc" }],
|
||||
select: { id: true, categoryId: true, paragraph: true, rule: true },
|
||||
});
|
||||
rules = await db
|
||||
.select({
|
||||
id: WebsiteRules.id,
|
||||
categoryId: WebsiteRules.categoryId,
|
||||
paragraph: WebsiteRules.paragraph,
|
||||
rule: WebsiteRules.rule,
|
||||
})
|
||||
.from(WebsiteRules)
|
||||
.orderBy(
|
||||
asc(WebsiteRules.categoryId),
|
||||
asc(WebsiteRules.paragraph),
|
||||
asc(WebsiteRules.id),
|
||||
);
|
||||
} catch {
|
||||
// DB unavailable — render the shell without rules.
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user