Initial commit
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { auth } from "@/auth";
|
||||
import { db } from "@/lib/db";
|
||||
|
||||
export async function GET(req: Request) {
|
||||
const session = await auth();
|
||||
if (!session?.user) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const q = searchParams.get("q") ?? "";
|
||||
const status = searchParams.get("status");
|
||||
|
||||
const projects = await db.project.findMany({
|
||||
where: {
|
||||
AND: [
|
||||
q
|
||||
? {
|
||||
OR: [
|
||||
{ name: { contains: q, mode: "insensitive" } },
|
||||
{ code: { contains: q, mode: "insensitive" } },
|
||||
],
|
||||
}
|
||||
: {},
|
||||
status ? { status: status as any } : {},
|
||||
],
|
||||
},
|
||||
orderBy: { createdAt: "desc" },
|
||||
include: {
|
||||
client: { select: { id: true, company: true } },
|
||||
producer: { select: { id: true, name: true, image: true } },
|
||||
_count: { select: { shots: true } },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ projects });
|
||||
}
|
||||
Reference in New Issue
Block a user