mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
search site
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import prisma from "@/app/prisma";
|
||||
import Fuse from "fuse.js";
|
||||
|
||||
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;
|
||||
@@ -18,8 +21,29 @@ export async function GET(request: NextRequest) {
|
||||
const sites = await prisma.site.findMany({
|
||||
skip,
|
||||
take,
|
||||
where: {
|
||||
name: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
description: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
});
|
||||
const total = await prisma.site.count({
|
||||
where: {
|
||||
name: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
description: {
|
||||
contains: search,
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
});
|
||||
const total = await prisma.site.count();
|
||||
return NextResponse.json({ sites, total, currentPage, itemPerPage }, { status: 200 });
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
||||
|
||||
Reference in New Issue
Block a user