import { NextRequest, NextResponse } from 'next/server'; import { auth } from '@clerk/nextjs/server'; import { getDatabase } from '@/lib/database'; // POST - Mark goal as complete export async function POST( req: NextRequest, { params }: { params: { id: string } } ) { try { const { userId } = await auth(); if (!userId) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const { id } = await params; const db = await getDatabase(); // Verify goal exists and user owns it const existingGoal = await db.getFitnessGoalById(id); if (!existingGoal) { return NextResponse.json({ error: 'Goal not found' }, { status: 404 }); } if (existingGoal.userId !== userId) { return NextResponse.json({ error: 'Forbidden' }, { status: 403 }); } // Mark as completed const completedGoal = await db.completeGoal(id); return NextResponse.json(completedGoal); } catch (error) { console.error('Error completing fitness goal:', error); return NextResponse.json( { error: 'Internal server error' }, { status: 500 } ); } }