import { NextRequest, NextResponse } from 'next/server'; import supabase from '@/lib/db'; // GET - Ambil semua nilai jenis_pendaftaran yang unik export async function GET() { try { // Ambil semua nilai jenis_pendaftaran yang unik const { data, error } = await supabase .from('mahasiswa') .select('jenis_pendaftaran') .not('jenis_pendaftaran', 'is', null) .order('jenis_pendaftaran'); if (error) { console.error('Error fetching jenis pendaftaran data:', error); return NextResponse.json({ message: 'Internal Server Error' }, { status: 500 }); } // Ambil nilai unik const uniqueValues = [...new Set(data.map(item => item.jenis_pendaftaran))]; return NextResponse.json(uniqueValues.map(value => ({ jenis_pendaftaran: value }))); } catch (error) { console.error('Error fetching jenis pendaftaran data:', error); return NextResponse.json({ message: 'Internal Server Error' }, { status: 500 }); } } // PUT - Update nilai jenis_pendaftaran export async function PUT(request: NextRequest) { try { const body = await request.json(); const { oldValue, newValue } = body; // Validasi field yang wajib diisi if (!oldValue || !newValue) { return NextResponse.json( { message: 'Missing required fields: oldValue, newValue' }, { status: 400 } ); } // Update jenis_pendaftaran const { data, error } = await supabase .from('mahasiswa') .update({ jenis_pendaftaran: newValue }) .eq('jenis_pendaftaran', oldValue) .select(); if (error) { console.error('Error updating jenis pendaftaran:', error); return NextResponse.json({ message: 'Internal Server Error' }, { status: 500 }); } return NextResponse.json({ message: 'Jenis pendaftaran updated successfully', affectedRows: data?.length || 0 }); } catch (error) { console.error('Error updating jenis pendaftaran:', error); return NextResponse.json({ message: 'Internal Server Error' }, { status: 500 }); } }