🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
47 lines
1.2 KiB
TypeScript
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 }
|
|
)
|
|
}
|
|
}
|