Files
recall/src/app/api/search/route.ts
2026-03-22 13:01:46 -03:00

42 lines
833 B
TypeScript

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<string, unknown> = {}
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)
}