rairo commited on
Commit
46e7291
·
verified ·
1 Parent(s): 5d9a295

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +4 -30
main.py CHANGED
@@ -417,7 +417,7 @@ def verify_admin(auth_header):
417
  def get_admin_overview():
418
  try:
419
  verify_admin(request.headers.get('Authorization', ''))
420
-
421
  users_ref = db.reference('users')
422
  all_users = users_ref.get() or {}
423
  users_list = []
@@ -427,53 +427,27 @@ def get_admin_overview():
427
  email = auth_user.email
428
  except:
429
  email = "Deleted User"
430
-
431
  users_list.append({
432
  'uid': uid,
433
  'email': email,
434
  'daily_cash': user_data.get('daily_cash', 0),
435
  'remaining_cash': user_data.get('remaining_cash', 0),
436
- 'last_reset': last_reset,
437
  'is_admin': user_data.get('is_admin', False)
438
  })
439
-
440
  transactions_ref = db.reference('transactions')
441
  all_transactions = transactions_ref.get() or {}
442
-
443
- transactions_list = []
444
- for tid, tx_data in all_transactions.items():
445
- tx_item = tx_data.copy()
446
- tx_item['id'] = tid
447
-
448
- # Format date if it exists
449
- if 'date' in tx_item:
450
- try:
451
- # Parse the date and convert to ISO format
452
- parsed_date = pd.to_datetime(tx_item['date'], errors='coerce')
453
- if pd.notnull(parsed_date):
454
- tx_item['date'] = parsed_date.isoformat()
455
- else:
456
- tx_item['date'] = '2000-01-01T00:00:00'
457
- except:
458
- # Default date if parsing fails
459
- tx_item['date'] = '2000-01-01T00:00:00'
460
-
461
- transactions_list.append(tx_item)
462
-
463
- # Replace NaN with None for JSON serialization
464
- transactions_list = pd.DataFrame(transactions_list).replace({np.nan: None}).to_dict(orient='records') if transactions_list else []
465
-
466
  return jsonify({
467
  'users': users_list,
468
  'transactions': transactions_list,
469
  'analytics': {
470
  'total_users': len(users_list),
471
  'total_transactions': len(transactions_list),
472
- 'total_spent': sum(t.get('total', 0) for t in transactions_list)
473
  }
474
  })
475
  except Exception as e:
476
- print(f"Error in admin overview: {e}")
477
  return jsonify({'error': str(e)}), 500
478
 
479
  @app.route('/api/admin/users', methods=['POST'])
 
417
  def get_admin_overview():
418
  try:
419
  verify_admin(request.headers.get('Authorization', ''))
420
+
421
  users_ref = db.reference('users')
422
  all_users = users_ref.get() or {}
423
  users_list = []
 
427
  email = auth_user.email
428
  except:
429
  email = "Deleted User"
 
430
  users_list.append({
431
  'uid': uid,
432
  'email': email,
433
  'daily_cash': user_data.get('daily_cash', 0),
434
  'remaining_cash': user_data.get('remaining_cash', 0),
435
+ 'last_reset': user_data.get('last_reset'),
436
  'is_admin': user_data.get('is_admin', False)
437
  })
 
438
  transactions_ref = db.reference('transactions')
439
  all_transactions = transactions_ref.get() or {}
440
+ transactions_list = [{'id': tid, **data} for tid, data in all_transactions.items()]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  return jsonify({
442
  'users': users_list,
443
  'transactions': transactions_list,
444
  'analytics': {
445
  'total_users': len(users_list),
446
  'total_transactions': len(transactions_list),
447
+ 'total_spent': sum(t['total'] for t in transactions_list)
448
  }
449
  })
450
  except Exception as e:
 
451
  return jsonify({'error': str(e)}), 500
452
 
453
  @app.route('/api/admin/users', methods=['POST'])