mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
54 lines
1.6 KiB
TypeScript
54 lines
1.6 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import prisma from "@/app/prisma";
|
|
|
|
interface QueryParams {
|
|
currentPage: number;
|
|
itemPerPage: number;
|
|
search: string;
|
|
}
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const { searchParams } = request.nextUrl;
|
|
const currentPage = Number(searchParams.get("currentPage")) || 1;
|
|
const itemPerPage = Number(searchParams.get("itemPerPage")) || 1;
|
|
const search = searchParams.get("search") || "";
|
|
|
|
const skip = (currentPage - 1) * itemPerPage;
|
|
const take = itemPerPage;
|
|
|
|
try {
|
|
const sites = await prisma.site.findMany({
|
|
skip,
|
|
take,
|
|
where: {
|
|
name: {
|
|
contains: search,
|
|
mode: "insensitive",
|
|
},
|
|
description: {
|
|
contains: search,
|
|
mode: "insensitive",
|
|
},
|
|
},
|
|
include: {
|
|
networks: true,
|
|
},
|
|
});
|
|
const total = await prisma.site.count({
|
|
where: {
|
|
name: {
|
|
contains: search,
|
|
mode: "insensitive",
|
|
},
|
|
description: {
|
|
contains: search,
|
|
mode: "insensitive",
|
|
},
|
|
},
|
|
});
|
|
return NextResponse.json({ sites, total, currentPage, itemPerPage }, { status: 200 });
|
|
} catch (error: any) {
|
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
|
}
|
|
}
|