U
    Ψ ζh
  γ                   @   s  e d  e d e d e d e d e d e d e d e d e d	 e d
 e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d e d  e d! d"S )#z2=== How to Debug the 500 Error on Your Server ===
z1. SSH into your server:z+   ssh your-user@timesheet.firsteconomy.comz
2. Check the application logs:z   # If using systemd:z/   sudo journalctl -u your-timesheet-service -fz   
   # If using PM2:z   pm2 logs timesheetz   
   # If using Docker:z%   docker logs -f timesheet-containerz#   
   # If using traditional logs:z'   tail -f /var/log/timesheet/error.logz
3. Check the web server logs:z   # Nginx:z(   sudo tail -f /var/log/nginx/error.logz   
   # Apache:z*   sudo tail -f /var/log/apache2/error.logz&
4. Common 500 error causes and fixes:z!
   A) Database Connection Error:z$      - Check if database is runningz%      - Verify connection credentialsz-      - Check if connection pool is exhaustedz!
   B) Query Error (most likely):z>      - Case sensitivity: 'riddhidhakhara' vs 'RiddhiDhakhara'z3      - Missing columns: category, application_namez      - Date format issuesz
   C) Memory/Resource Issues:z$      - Check server memory: free -hz      - Check disk space: df -hz      - Restart the applicationz
5. Quick test on the server:a<  
   # Create a test script on the server:
   python3 << 'EOF'
import psycopg2
import json
from datetime import date

# Connect to database
conn = psycopg2.connect(
    host="localhost",
    database="timesheet_db",
    user="your_db_user",
    password="your_db_password"
)

cur = conn.cursor()

# Test the problematic query
developer_id = 'riddhidhakhara'
start_date = '2025-09-30'
end_date = '2025-10-08'

try:
    # Case-insensitive query
    cur.execute('''
        SELECT COUNT(*) 
        FROM activity_records 
        WHERE LOWER(CAST(developer_id AS VARCHAR)) = LOWER(%s)
        AND DATE(timestamp) BETWEEN %s AND %s
    ''', (developer_id, start_date, end_date))
    
    count = cur.fetchone()[0]
    print(f"Found {count} records")
    
except Exception as e:
    print(f"Error: {e}")

cur.close()
conn.close()
EOF
z(
6. Emergency fix - Update the API code:aI  
   Find your API endpoint file and update the query to be case-insensitive.
   
   Look for something like:
   - api/routes/activity.py
   - controllers/activityController.js
   - src/api/activities.js
   
   And change queries from:
   WHERE developer_id = ?
   
   To:
   WHERE LOWER(CAST(developer_id AS VARCHAR)) = LOWER(?)
N)Ϊprint© r   r   ϊ./check_api_logs.pyΪ<module>   sB   *