25 lines
845 B
TypeScript
25 lines
845 B
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { auth } from '@/auth'
|
|
import prisma from '@/lib/prisma'
|
|
|
|
/** Liste hiérarchique des carnets pour le clipper (extension). */
|
|
export async function GET(_request: NextRequest) {
|
|
try {
|
|
const session = await auth()
|
|
if (!session?.user?.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const notebooks = await prisma.notebook.findMany({
|
|
where: { userId: session.user.id, trashedAt: null },
|
|
select: { id: true, name: true, parentId: true, color: true },
|
|
orderBy: [{ order: 'asc' }, { name: 'asc' }],
|
|
})
|
|
|
|
return NextResponse.json({ notebooks })
|
|
} catch (error) {
|
|
console.error('[GET /api/clip/notebooks]', error)
|
|
return NextResponse.json({ error: 'Failed to load notebooks' }, { status: 500 })
|
|
}
|
|
}
|