First commit
This commit is contained in:
51
app/api/mahasiswa/lulus-tepat-waktu/route.ts
Normal file
51
app/api/mahasiswa/lulus-tepat-waktu/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import pool from '@/lib/db';
|
||||
|
||||
interface LulusTepatWaktu {
|
||||
tahun_angkatan: number;
|
||||
jk: string;
|
||||
jumlah_lulus_tepat_waktu: number;
|
||||
}
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const tahunAngkatan = searchParams.get('tahun_angkatan');
|
||||
|
||||
let query = `
|
||||
SELECT
|
||||
m.tahun_angkatan,
|
||||
m.jk,
|
||||
COUNT(m.nim) AS jumlah_lulus_tepat_waktu
|
||||
FROM
|
||||
mahasiswa m
|
||||
JOIN
|
||||
status_mahasiswa s ON m.nim = s.nim
|
||||
WHERE
|
||||
s.status_kuliah = 'Lulus'
|
||||
AND s.semester <= 8
|
||||
`;
|
||||
|
||||
const params: any[] = [];
|
||||
|
||||
if (tahunAngkatan && tahunAngkatan !== 'all') {
|
||||
query += ' AND m.tahun_angkatan = ?';
|
||||
params.push(tahunAngkatan);
|
||||
}
|
||||
|
||||
query += `
|
||||
GROUP BY
|
||||
m.tahun_angkatan, m.jk
|
||||
ORDER BY
|
||||
m.tahun_angkatan DESC, m.jk
|
||||
`;
|
||||
|
||||
const [rows] = await pool.query(query, params);
|
||||
return NextResponse.json(rows);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Internal Server Error' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user