import { NextRequest, NextResponse } from 'next/server' import { prisma } from '@/lib/prisma' export async function GET(req: NextRequest) { const { searchParams } = new URL(req.url) const q = searchParams.get('q') || '' const type = searchParams.get('type') const tag = searchParams.get('tag') const where: Record = {} if (q) { where.OR = [ { title: { contains: q } }, { content: { contains: q } }, ] } if (type) { where.type = type } if (tag) { where.tags = { some: { tag: { name: tag }, }, } } const notes = await prisma.note.findMany({ where, include: { tags: { include: { tag: true } } }, orderBy: [ { isPinned: 'desc' }, { updatedAt: 'desc' }, ], }) return NextResponse.json(notes) }