Skip to content

Latest commit

 

History

History
69 lines (55 loc) · 2.41 KB

File metadata and controls

69 lines (55 loc) · 2.41 KB

🔧 Event Approval System Fix

❌ Problem Identified:

University Event Approval component showed "No events found" even though events were created.

🎯 Root Cause:

The GET /api/events/requests route was still using the old User.findById(req.user.id) pattern instead of the new getUserFromRole() helper function that looks in the correct collection (Alumni, Student, University).

✅ What I Fixed:

1. Backend Routes Updated:

  • GET /api/events/requests - Now uses getUserFromRole() to find university admin
  • PUT /api/events/requests/:id/approve - Updated to use correct user lookup
  • PUT /api/events/requests/:id/reject - Updated to use correct user lookup
  • All user ID references - Changed from req.user.id to userId variable

2. Added Debug Logging:

console.log('🔍 GET /api/events/requests - req.user:', req.user);
console.log('✅ User found:', user.email, 'Role:', userRole);
console.log('🔍 Query for event requests:', query);
console.log('✅ Found', requests.length, 'event requests');

3. Frontend Debug Logging:

console.log('🔍 Fetching event requests with params:', queryParams.toString());
console.log('🔍 Response status:', response.status);
console.log('✅ Event requests data:', data);

🚀 How to Test:

  1. Login as University Admin
  2. Go to University Dashboard
  3. Check the Event Requests section
  4. Look at browser console for debug logs
  5. Look at backend console for debug logs

📋 Expected Debug Output:

Frontend:

🔍 Fetching event requests with params: 
🔍 Response status: 200
✅ Event requests data: {requests: [...], pagination: {...}}

Backend:

🔍 GET /api/events/requests - req.user: {id: "...", role: "university"}
✅ User found: university@example.com Role: university
🔍 Query for event requests: {}
✅ Found 1 event requests
🔍 Sample request: {_id: "...", title: "...", status: "Pending"}

🎯 Expected Result:

✅ Event requests should now appear in the University Dashboard
✅ University admin can approve/reject events
✅ Full event approval workflow works

🔄 Complete Workflow:

  1. Alumni creates event → EventRequest saved
  2. University admin sees it in dashboard → Can approve/reject
  3. Approved events become visible to students
  4. Students can register for events

The event approval system should now be fully functional! 🎉