Files
Momento/memento-note/app/api/blocks/embed/route.ts
Antigravity e2672cd2c2
Some checks failed
CI / Lint, Test & Build (push) Failing after 1m19s
CI / Deploy production (on server) (push) Has been skipped
feat(notes): liens internes, onglet Réseau, living blocks et consentement IA
Rend les liens entre notes visibles et persistants (sync NoteLink au save, auto-save, graphe réseau rafraîchi), ajoute living blocks, Memory Echo, recherche globale, consentement IA explicite et consolide les prototypes design en architectural-grid.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-24 14:27:29 +00:00

45 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import prisma from '@/lib/prisma'
import { auth } from '@/auth'
// POST /api/blocks/embed
// Body: { sourceNoteId, blockId, targetNoteId }
export async function POST(request: NextRequest) {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const body = await request.json()
const { sourceNoteId, blockId, targetNoteId } = body
if (!sourceNoteId || !blockId || !targetNoteId) {
return NextResponse.json({ error: 'sourceNoteId, blockId and targetNoteId are required' }, { status: 400 })
}
// Verify both notes belong to the user
const [sourceNote, targetNote] = await Promise.all([
prisma.note.findFirst({ where: { id: sourceNoteId, userId: session.user.id } }),
prisma.note.findFirst({ where: { id: targetNoteId, userId: session.user.id } }),
])
if (!sourceNote || !targetNote) {
return NextResponse.json({ error: 'Note not found or unauthorized' }, { status: 404 })
}
// Upsert — avoid duplicate refs
const existing = await prisma.liveBlockRef.findFirst({
where: { sourceNoteId, blockId, targetNoteId },
})
if (existing) {
return NextResponse.json({ id: existing.id, created: false })
}
const ref = await prisma.liveBlockRef.create({
data: { sourceNoteId, blockId, targetNoteId },
})
return NextResponse.json({ id: ref.id, created: true })
}