import { NextRequest, NextResponse } from 'next/server' import prisma from '@/lib/prisma' import { getMobileUserId } from '@/lib/mobile-auth' export async function GET(req: NextRequest) { const userId = getMobileUserId(req) if (!userId) return NextResponse.json({ error: 'Non autorisé' }, { status: 401 }) const { searchParams } = new URL(req.url) const notebookId = searchParams.get('notebookId') const notes = await prisma.note.findMany({ where: { userId, trashedAt: null, ...(notebookId ? { notebookId } : {}), }, select: { id: true, title: true, updatedAt: true, color: true, notebook: { select: { name: true } }, }, orderBy: { updatedAt: 'desc' }, take: 50, }) const notebookName = notebookId ? (await prisma.notebook.findUnique({ where: { id: notebookId }, select: { name: true } }))?.name : undefined return NextResponse.json({ notes: notes.map((n) => ({ id: n.id, title: n.title, updatedAt: n.updatedAt, color: n.color, notebookName: n.notebook?.name, })), ...(notebookName ? { notebookName } : {}), }) }