testing yuk
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import supabase from '@/lib/db';
|
||||
|
||||
// GET - Fetch all prestasi mahasiswa or filter by criteria
|
||||
// GET - Ambil semua data prestasi mahasiswa atau filter berdasarkan kriteria
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
@@ -109,7 +109,7 @@ export async function GET(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// POST - Create a new prestasi mahasiswa
|
||||
// POST - Buat data prestasi mahasiswa baru
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
@@ -196,7 +196,7 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// PUT - Update an existing prestasi mahasiswa
|
||||
// PUT - Update data prestasi mahasiswa yang sudah ada
|
||||
export async function PUT(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
@@ -296,7 +296,7 @@ export async function PUT(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// DELETE - Delete a prestasi mahasiswa
|
||||
// DELETE - Hapus data prestasi mahasiswa
|
||||
export async function DELETE(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
|
||||
@@ -334,14 +334,14 @@ async function insertDataToDatabase(data: any[]) {
|
||||
console.log(`Total data items to process: ${data.length}`);
|
||||
console.log('Sample data items:', data.slice(0, 3));
|
||||
|
||||
// First, validate all NIMs exist before processing
|
||||
// Pertama, validasi semua NIM ada sebelum diproses
|
||||
const uniqueNims = [...new Set(data.map(item => item.nim))];
|
||||
console.log(`Unique NIMs found: ${uniqueNims.length}`);
|
||||
console.log('Unique NIMs:', uniqueNims);
|
||||
|
||||
const nimValidationMap = new Map();
|
||||
|
||||
// Batch check all NIMs for existence
|
||||
// Cek batch semua NIM untuk keberadaan
|
||||
console.log('=== DEBUG: Starting NIM validation ===');
|
||||
for (const nim of uniqueNims) {
|
||||
try {
|
||||
@@ -370,7 +370,7 @@ async function insertDataToDatabase(data: any[]) {
|
||||
console.log('=== DEBUG: NIM validation results ===');
|
||||
console.log('Validation map:', Object.fromEntries(nimValidationMap));
|
||||
|
||||
// Process each data item
|
||||
// Proses setiap item data
|
||||
console.log('=== DEBUG: Starting prestasi data processing ===');
|
||||
for (const item of data) {
|
||||
try {
|
||||
@@ -390,7 +390,7 @@ async function insertDataToDatabase(data: any[]) {
|
||||
|
||||
console.log(`✅ NIM ${item.nim} is valid, proceeding with prestasi check/insert`);
|
||||
|
||||
// Check if prestasi already exists for this mahasiswa
|
||||
// Cek apakah prestasi sudah ada untuk mahasiswa ini
|
||||
console.log(`Checking existing prestasi for mahasiswa ID: ${nimValidation.id_mahasiswa}, nama_prestasi: ${item.nama_prestasi}, tanggal: ${item.tanggal_prestasi}`);
|
||||
const { data: existingPrestasi, error: prestasiCheckError } = await supabase
|
||||
.from('prestasi_mahasiswa')
|
||||
@@ -406,7 +406,7 @@ async function insertDataToDatabase(data: any[]) {
|
||||
|
||||
if (existingPrestasi) {
|
||||
console.log(`📝 Updating existing prestasi (ID: ${existingPrestasi.id_prestasi})`);
|
||||
// Update existing prestasi
|
||||
// Update prestasi yang sudah ada
|
||||
const { error: updateError } = await supabase
|
||||
.from('prestasi_mahasiswa')
|
||||
.update({
|
||||
@@ -428,7 +428,7 @@ async function insertDataToDatabase(data: any[]) {
|
||||
}
|
||||
} else {
|
||||
console.log(`📝 Inserting new prestasi for mahasiswa ID: ${nimValidation.id_mahasiswa}`);
|
||||
// Insert new prestasi
|
||||
// Insert prestasi baru
|
||||
const { error: insertError } = await supabase
|
||||
.from('prestasi_mahasiswa')
|
||||
.insert({
|
||||
|
||||
Reference in New Issue
Block a user