All files / app/api/subscriptions/plans route.ts

100% Statements 19/19
100% Branches 5/5
100% Functions 1/1
100% Lines 19/19

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 25 26 27 28 29 30 31 321x                 4x 4x 4x     4x 4x 4x 4x 4x   4x 1x 1x 1x   2x 4x 1x 1x 1x 4x  
/**
 * Subscription Plans API
 *
 * GET /api/subscriptions/plans - Get all available plans
 */
 
import { NextResponse } from 'next/server';
import { getAdminClient } from '@/lib/supabase/admin';
 
export async function GET() {
  try {
    const adminClient = getAdminClient();
 
    // Get all active plans
    const { data: plans, error } = await adminClient
      .from('subscription_plans')
      .select('*')
      .eq('is_active', true)
      .order('price', { ascending: true });
 
    if (error) {
      console.error('Error fetching plans:', error);
      return NextResponse.json({ error: 'Failed to fetch plans' }, { status: 500 });
    }
 
    return NextResponse.json({ plans });
  } catch (error) {
    console.error('Get plans error:', error);
    return NextResponse.json({ error: 'Failed to get plans' }, { status: 500 });
  }
}