backend troubleshooting
This commit is contained in:
parent
8ea8dc66a6
commit
4e4160f9f1
@ -299,7 +299,6 @@ def submit_absensi():
|
|||||||
def get_jadwal_today():
|
def get_jadwal_today():
|
||||||
try:
|
try:
|
||||||
# 1. TRIGGER AUTO ALFA
|
# 1. TRIGGER AUTO ALFA
|
||||||
# Jalankan pengecekan otomatis SEBELUM mengambil data jadwal
|
|
||||||
jalankan_auto_alfa()
|
jalankan_auto_alfa()
|
||||||
|
|
||||||
# 2. Ambil Data Jadwal
|
# 2. Ambil Data Jadwal
|
||||||
@ -319,11 +318,17 @@ def get_jadwal_today():
|
|||||||
""", (hari_ini, mhs['jurusan'], mhs['semester']))
|
""", (hari_ini, mhs['jurusan'], mhs['semester']))
|
||||||
jadwal = cur.fetchall()
|
jadwal = cur.fetchall()
|
||||||
|
|
||||||
|
# === FIX ERROR TIMEDELTA DISINI ===
|
||||||
for j in jadwal:
|
for j in jadwal:
|
||||||
if isinstance(j['jam_mulai'], timedelta): j['jam_mulai'] = str(j['jam_mulai'])
|
# Ubah jam_mulai (timedelta) ke string "HH:MM:SS"
|
||||||
if isinstance(j['jam_selesai'], timedelta): j['jam_selesai'] = str(j['jam_selesai'])
|
if isinstance(j.get('jam_mulai'), timedelta):
|
||||||
|
j['jam_mulai'] = str(j['jam_mulai'])
|
||||||
|
|
||||||
# Ambil Status Absensi (HADIR / TIDAK HADIR / SAKIT / IZIN)
|
# Ubah jam_selesai (timedelta) ke string "HH:MM:SS"
|
||||||
|
if isinstance(j.get('jam_selesai'), timedelta):
|
||||||
|
j['jam_selesai'] = str(j['jam_selesai'])
|
||||||
|
|
||||||
|
# Cek Status Absensi
|
||||||
cur.execute("""
|
cur.execute("""
|
||||||
SELECT status FROM absensi
|
SELECT status FROM absensi
|
||||||
WHERE id_mahasiswa=%s AND id_jadwal=%s AND DATE(timestamp)=CURDATE()
|
WHERE id_mahasiswa=%s AND id_jadwal=%s AND DATE(timestamp)=CURDATE()
|
||||||
@ -341,24 +346,32 @@ def get_jadwal_today():
|
|||||||
cur.close(); conn.close()
|
cur.close(); conn.close()
|
||||||
return jsonify({'data': jadwal, 'hari': hari_ini})
|
return jsonify({'data': jadwal, 'hari': hari_ini})
|
||||||
|
|
||||||
except Exception as e: return jsonify({'error': str(e)}), 500
|
except Exception as e:
|
||||||
|
print(f"Error Jadwal: {e}") # Print error di terminal agar jelas
|
||||||
|
return jsonify({'error': str(e)}), 500
|
||||||
|
|
||||||
@app.route('/api/absensi/history', methods=['GET'])
|
@app.route('/api/absensi/history', methods=['GET'])
|
||||||
@token_required
|
@token_required
|
||||||
def get_history():
|
def get_history():
|
||||||
connection = get_db_connection()
|
connection = get_db_connection()
|
||||||
cursor = connection.cursor(dictionary=True)
|
cursor = connection.cursor(dictionary=True)
|
||||||
# Join jadwal untuk ambil jam
|
|
||||||
cursor.execute("""
|
cursor.execute("""
|
||||||
SELECT a.*, j.jam_mulai, j.jam_selesai
|
SELECT a.*, j.jam_mulai, j.jam_selesai
|
||||||
FROM absensi a
|
FROM absensi a
|
||||||
LEFT JOIN jadwal_kelas j ON a.id_jadwal = j.id_jadwal
|
LEFT JOIN jadwal_kelas j ON a.id_jadwal = j.id_jadwal
|
||||||
WHERE a.id_mahasiswa = %s ORDER BY a.timestamp DESC
|
WHERE a.id_mahasiswa = %s ORDER BY a.timestamp DESC
|
||||||
""", (request.user_data['id_mahasiswa'],))
|
""", (request.user_data['id_mahasiswa'],))
|
||||||
|
|
||||||
history = cursor.fetchall()
|
history = cursor.fetchall()
|
||||||
|
|
||||||
|
# === FIX ERROR TIMEDELTA DISINI ===
|
||||||
for item in history:
|
for item in history:
|
||||||
if item['jam_mulai']: item['jam_mulai'] = str(item['jam_mulai'])
|
if isinstance(item.get('jam_mulai'), timedelta):
|
||||||
if item['jam_selesai']: item['jam_selesai'] = str(item['jam_selesai'])
|
item['jam_mulai'] = str(item['jam_mulai'])
|
||||||
|
if isinstance(item.get('jam_selesai'), timedelta):
|
||||||
|
item['jam_selesai'] = str(item['jam_selesai'])
|
||||||
|
|
||||||
cursor.close(); connection.close()
|
cursor.close(); connection.close()
|
||||||
return jsonify({'data': history}), 200
|
return jsonify({'data': history}), 200
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user