Coba Terus

This commit is contained in:
Randa Firman Putra
2025-08-23 22:45:23 +07:00
parent 744c3db464
commit be030b8510
8 changed files with 1007 additions and 19 deletions

View File

@@ -0,0 +1,60 @@
import { NextResponse } from 'next/server';
import supabase from '@/lib/db';
export async function GET(request: Request) {
try {
// Get all mahasiswa data and process in JavaScript
const { data: mahasiswaData, error } = await supabase
.from('mahasiswa')
.select('provinsi');
if (error) {
console.error('Supabase error:', error);
return NextResponse.json(
{ error: 'Database error' },
{ status: 500 }
);
}
// Process the data in JavaScript
let kalimantanBarat = 0;
let luarKalimantanBarat = 0;
mahasiswaData.forEach((mahasiswa) => {
const provinsi = mahasiswa.provinsi?.toLowerCase() || '';
if (provinsi.includes('kalimantan barat') || provinsi.includes('kalbar')) {
kalimantanBarat++;
} else if (mahasiswa.provinsi) {
luarKalimantanBarat++;
}
});
// Transform the data to match the expected format
const result = [
{
provinsi: 'Kalimantan Barat',
jumlah_mahasiswa: kalimantanBarat
},
{
provinsi: 'Luar Kalimantan Barat',
jumlah_mahasiswa: luarKalimantanBarat
}
];
return NextResponse.json(result, {
headers: {
'Cache-Control': 'public, max-age=60, stale-while-revalidate=30',
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
});
} catch (error) {
console.error('Error fetching provinsi data:', error);
return NextResponse.json(
{ error: 'Internal Server Error' },
{ status: 500 }
);
}
}