Files
var-monorepo/apps/hub/app/_components/pagiantedTableActions.ts
2025-12-27 15:33:00 +01:00

41 lines
735 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
"use server";
import { prisma, PrismaClient } from "@repo/db";
export async function getData<Twhere>({
model,
limit,
offset,
where,
include,
orderBy,
select,
}: {
model: keyof PrismaClient;
limit: number;
offset: number;
where: Twhere;
include?: Record<string, boolean>;
orderBy?: Record<string, "asc" | "desc">;
select?: Record<string, any>;
}) {
if (!model || !(prisma as any)[model]) {
return { data: [], total: 0 };
}
const delegate = (prisma as any)[model];
const data = await delegate.findMany({
where,
orderBy,
take: limit,
skip: offset,
include,
select,
});
const total = await delegate.count({ where });
return { data, total };
}