Files
EpicNext-Cms/src/app/admin/polls/page.tsx
T
openhands 56061e41d4
CI / check (push) Failing after 12s
CI / deploy (push) Skipped
CI / release (push) Skipped
refactor: replace Prisma ORM runtime with Drizzle ORM facade
- Replace Prisma client runtime with Drizzle ORM (zero Prisma engine/query engine in production)
- Add Prisma-compatible facade (@/lib/prisma-facade.ts) backed by Drizzle for backwards compatibility
- Runtime queries route through Drizzle ORM; @prisma/client is now devDependency (types only)
- Remove @prisma/adapter-mariadb dependency; delete prisma-pool.ts and types/prisma.ts
- New Drizzle schema layer: src/db/schema.ts (176 tables) and src/lib/db.ts (connection)
- Update README documenting the dual-layer ORM architecture
- Restore src/generated/ gitignore (build artifact for local type generation)
- 0 TypeScript errors, 583 tests passing

The facade intentionally uses `any` types to match the Prisma Client API surface,
allowing existing code to run unmodified while routing queries through Drizzle at runtime.
2026-07-31 14:11:03 +02:00

71 lines
1.9 KiB
TypeScript

import { count, desc, like } from "drizzle-orm";
import Link from "next/link";
import { getTranslations } from "next-intl/server";
import { Button } from "@/components/ui/button";
import { fetchAdminList } from "@/lib/admin-list";
import { db, WebsitePoll } from "@/lib/db";
import { PERMS } from "@/lib/permissions";
import { PollsTable } from "./polls-table";
export default async function PollsPage({
params: paramsPromise,
searchParams,
}: {
params: Promise<{ locale: string }>;
searchParams: Promise<Record<string, string>>;
}) {
const t = await getTranslations("pages.admin.polls");
const result = await fetchAdminList(
{
permission: PERMS.POLLS_VIEW,
fetch: async ({ search, page, perPage }) => {
const where = search
? like(WebsitePoll.title, `%${search}%`)
: undefined;
const [rows, totals] = await Promise.all([
db
.select({
id: WebsitePoll.id,
title: WebsitePoll.title,
status: WebsitePoll.status,
showResults: WebsitePoll.showResults,
multipleChoice: WebsitePoll.multipleChoice,
startsAt: WebsitePoll.startsAt,
endsAt: WebsitePoll.endsAt,
createdAt: WebsitePoll.createdAt,
})
.from(WebsitePoll)
.where(where)
.orderBy(desc(WebsitePoll.createdAt))
.limit(perPage)
.offset((page - 1) * perPage),
db.select({ total: count() }).from(WebsitePoll).where(where),
]);
return { rows, total: totals[0]?.total ?? 0 };
},
},
paramsPromise,
searchParams,
);
return (
<div className="space-y-6">
<div className="flex justify-end">
<Button variant="default" asChild>
<Link href="/admin/polls/create">{t("newPoll")}</Link>
</Button>
</div>
<PollsTable
data={{
rows: result.rows,
total: result.total,
page: result.page,
perPage: result.perPage,
lastPage: result.lastPage,
}}
/>
</div>
);
}