All files / varjoliitokauppa/app/api/admin/reviews route.ts

62.5% Statements 5/8
50% Branches 1/2
100% Functions 1/1
71.42% Lines 5/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24            1x 1x   1x 1x             1x            
import { NextResponse } from 'next/server'
import { prisma } from '@/lib/prisma'
import { checkAdminAuth } from '@/lib/auth-check'
 
// GET /api/admin/reviews - Get all reviews (Admin only)
export async function GET() {
  const authError = await checkAdminAuth()
  Iif (authError) return authError
 
  try {
    const reviews = await prisma.review.findMany({
      include: {
        product: true,
      },
      orderBy: { createdAt: 'desc' },
    })
 
    return NextResponse.json(reviews)
  } catch (error) {
    console.error('Error fetching reviews:', error)
    return NextResponse.json({ error: 'Failed to fetch reviews' }, { status: 500 })
  }
}