tes lagi
This commit is contained in:
69
app/api/tabeldetail/kk-lulus-tepat/route.ts
Normal file
69
app/api/tabeldetail/kk-lulus-tepat/route.ts
Normal file
@@ -0,0 +1,69 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import supabase from '@/lib/db';
|
||||
|
||||
interface MahasiswaKKLulusTepat {
|
||||
nim: string;
|
||||
nama: string;
|
||||
tahun_angkatan: number;
|
||||
nama_kelompok_keahlian: string;
|
||||
semester: number;
|
||||
}
|
||||
|
||||
// GET - Ambil data mahasiswa lulus tepat waktu dengan kelompok keahlian dan filter tahun angkatan untuk tabel detail
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tahunAngkatan = searchParams.get('tahun_angkatan');
|
||||
|
||||
let query = supabase
|
||||
.from('mahasiswa')
|
||||
.select(`
|
||||
nim,
|
||||
nama,
|
||||
tahun_angkatan,
|
||||
semester,
|
||||
kelompok_keahlian!inner(nama_kelompok)
|
||||
`)
|
||||
.eq('status_kuliah', 'Lulus') // Hanya mahasiswa yang sudah lulus
|
||||
.lte('semester', 8) // Lulus tepat waktu (maksimal 8 semester)
|
||||
.order('semester', { ascending: true }); // Urutkan berdasarkan semester tercepat
|
||||
|
||||
// Jika ada filter tahun angkatan, terapkan filter
|
||||
if (tahunAngkatan && tahunAngkatan !== 'all') {
|
||||
query = query.eq('tahun_angkatan', parseInt(tahunAngkatan));
|
||||
}
|
||||
|
||||
const { data, error } = await query;
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
return NextResponse.json(
|
||||
{ message: 'Failed to fetch data', error: error.message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
// Transform data untuk meratakan field yang di-join
|
||||
const transformedData: MahasiswaKKLulusTepat[] = (data || []).map((item: any) => ({
|
||||
nim: item.nim,
|
||||
nama: item.nama,
|
||||
tahun_angkatan: item.tahun_angkatan,
|
||||
semester: item.semester,
|
||||
nama_kelompok_keahlian: item.kelompok_keahlian?.nama_kelompok || ''
|
||||
}));
|
||||
|
||||
return NextResponse.json(transformedData, {
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0',
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error in tabeldetail/kk-lulus-tepat API:', error);
|
||||
return NextResponse.json(
|
||||
{ message: 'Internal Server Error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user