Files
fairreview/src/app/api/reviews/[id]/vote/route.ts
zhuma 70726c50dc fix: resolve multiple runtime and build issues
- Fix network binding to allow external access (0.0.0.0)
- Upgrade to Node.js 20.x for Next.js 16 compatibility
- Fix next-auth v4 configuration and session handling
- Add Steam client secret for Steam OAuth provider
- Fix Prisma schema unique constraint syntax
- Fix database creation script for automated deployment
- Fix game search API to use new IStoreService endpoint
- Fix session auth in API routes for Steam linking
- Add TypeScript types for next-auth session
2026-02-21 22:51:45 +00:00

62 lines
1.4 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { auth } from '@/lib/auth'
import { prisma } from '@/lib/db'
export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const session = await auth()
if (!session?.user?.id) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
}
const resolvedParams = await params
const { voteType } = await request.json()
if (voteType !== 1 && voteType !== -1) {
return NextResponse.json({ error: 'Invalid vote type' }, { status: 400 })
}
const review = await prisma.review.findUnique({
where: { id: resolvedParams.id }
})
if (!review) {
return NextResponse.json({ error: 'Review not found' }, { status: 404 })
}
const existingVote = await prisma.vote.findUnique({
where: {
user_review_unique: {
userId: session.user.id,
reviewId: resolvedParams.id
}
}
})
if (existingVote) {
if (existingVote.voteType === voteType) {
await prisma.vote.delete({
where: { id: existingVote.id }
})
} else {
await prisma.vote.update({
where: { id: existingVote.id },
data: { voteType: voteType }
})
}
} else {
await prisma.vote.create({
data: {
userId: session.user.id,
reviewId: resolvedParams.id,
voteType: voteType
}
})
}
return NextResponse.json({ success: true })
}