Files
biblical-guide.com/app/api/highlights/route.ts
2025-11-12 07:07:21 +00:00

47 lines
1.2 KiB
TypeScript

import { NextResponse } from 'next/server'
import { prisma } from '@/lib/db'
import { getAuth } from '@clerk/nextjs/server'
export const runtime = 'nodejs'
export async function POST(request: Request) {
try {
const { userId } = await getAuth(request)
if (!userId) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const body = await request.json()
const { verseId, color } = body
if (!verseId || !['yellow', 'orange', 'pink', 'blue'].includes(color)) {
return NextResponse.json({ error: 'Invalid input' }, { status: 400 })
}
const highlight = await prisma.userHighlight.create({
data: {
userId,
verseId,
color,
createdAt: new Date(),
updatedAt: new Date()
}
})
return NextResponse.json({
id: highlight.id,
verseId: highlight.verseId,
color: highlight.color,
createdAt: highlight.createdAt.getTime(),
updatedAt: highlight.updatedAt.getTime(),
syncStatus: 'synced'
})
} catch (error) {
console.error('Error creating highlight:', error)
return NextResponse.json(
{ error: 'Failed to create highlight' },
{ status: 500 }
)
}
}