- Verified all exports in highlight-manager.ts are correct - Installed @clerk/nextjs dependency for API routes - Fixed TypeScript errors in API routes (NextRequest type) - Fixed MUI Grid component usage in highlights-tab.tsx (replaced with Box flexbox) - Fixed HighlightColor type assertion in reading-view.tsx - Build completed successfully with no TypeScript errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
74 lines
1.8 KiB
TypeScript
74 lines
1.8 KiB
TypeScript
import { NextResponse, NextRequest } from 'next/server'
|
|
import { prisma } from '@/lib/db'
|
|
import { getAuth } from '@clerk/nextjs/server'
|
|
|
|
export const runtime = 'nodejs'
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const { userId } = await getAuth(request)
|
|
if (!userId) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
|
|
}
|
|
|
|
const body = await request.json()
|
|
const { highlights } = body
|
|
|
|
if (!Array.isArray(highlights)) {
|
|
return NextResponse.json({ error: 'Invalid input' }, { status: 400 })
|
|
}
|
|
|
|
const synced = []
|
|
const errors = []
|
|
|
|
for (const item of highlights) {
|
|
try {
|
|
const existing = await prisma.userHighlight.findFirst({
|
|
where: {
|
|
userId,
|
|
verseId: item.verseId
|
|
}
|
|
})
|
|
|
|
if (existing) {
|
|
await prisma.userHighlight.update({
|
|
where: { id: existing.id },
|
|
data: {
|
|
color: item.color,
|
|
updatedAt: new Date()
|
|
}
|
|
})
|
|
} else {
|
|
await prisma.userHighlight.create({
|
|
data: {
|
|
userId,
|
|
verseId: item.verseId,
|
|
color: item.color,
|
|
createdAt: new Date(),
|
|
updatedAt: new Date()
|
|
}
|
|
})
|
|
}
|
|
synced.push(item.verseId)
|
|
} catch (e) {
|
|
errors.push({
|
|
verseId: item.verseId,
|
|
error: 'Failed to sync'
|
|
})
|
|
}
|
|
}
|
|
|
|
return NextResponse.json({
|
|
synced: synced.length,
|
|
errors,
|
|
serverTime: Date.now()
|
|
})
|
|
} catch (error) {
|
|
console.error('Error bulk syncing highlights:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Failed to sync highlights' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|