completed paginated Component
This commit is contained in:
24
apps/hub/app/_components/pagiantedTableActions.ts
Normal file
24
apps/hub/app/_components/pagiantedTableActions.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
'use server';
|
||||
import { PrismaClient } from '@repo/db';
|
||||
|
||||
export const getData = async (
|
||||
prismaModelName: keyof PrismaClient,
|
||||
take: number,
|
||||
skip: number
|
||||
) => {
|
||||
const prisma = new PrismaClient();
|
||||
if (
|
||||
!prismaModelName ||
|
||||
!prisma[prismaModelName] ||
|
||||
!('findMany' in prisma[prismaModelName])
|
||||
)
|
||||
return;
|
||||
const model = prisma[prismaModelName] as any;
|
||||
if (!model.findMany || !model.count) return;
|
||||
const data = await model.findMany({
|
||||
take,
|
||||
skip,
|
||||
});
|
||||
const total = await model.count();
|
||||
return { data, total };
|
||||
};
|
||||
Reference in New Issue
Block a user