feat(critical): Implement critical Aperture features

TASK 1: Implement GET /api/aperture/stats
- Create endpoint at app/api/aperture/stats/route.ts
- Returns dashboard statistics: { totalBookings, totalRevenue, completedToday, upcomingToday }
- Calculates stats from bookings table by month and today
- Dashboard now has functional statistics display

TASK 2: Implement authentication for Aperture
- Create middleware.ts for protecting Aperture routes
- Only allows access to users with admin, manager, or staff roles
- Redirects unauthorized users to /aperture/login
- Uses Supabase Auth with session verification
- Integrates with existing AuthProvider in lib/auth/context.tsx

Stack Updates:
- Update @supabase/auth-helpers-nextjs to latest version (0.15.0)
- Note: Package marked as deprecated but still functional

Files Created:
- app/api/aperture/stats/route.ts
- middleware.ts

Files Modified:
- TASKS.md (marked tasks 1 and 2 as completed)
- package.json (updated dependency)

Impact:
- Aperture dashboard now has working statistics
- Aperture routes are now protected by authentication
- Only authorized staff/admin/manager can access dashboard

Next: Task 3 - Implement weekly invitation reset
This commit is contained in:
Marco Gallegos
2026-01-17 10:48:40 -06:00
parent 46f476a622
commit e33a9a4573
5 changed files with 184 additions and 47 deletions

View File

@@ -519,17 +519,17 @@ Validación Staff (rol Staff):
### 🔴 CRÍTICO - Bloquea Funcionamiento (Timeline: 1-2 días)
1. **Implementar `GET /api/aperture/stats`** - ~30 min
- Dashboard de Aperture espera este endpoint
- Sin esto, estadísticas no se cargan
- Respuesta esperada: `{ success: true, stats: { totalBookings, totalRevenue, completedToday, upcomingToday } }`
- Ubicación: `app/api/aperture/stats/route.ts`
1. **Implementar `GET /api/aperture/stats`** - COMPLETADO
- Dashboard de Aperture espera este endpoint
- Sin esto, estadísticas no se cargan
- Respuesta esperada: `{ success: true, stats: { totalBookings, totalRevenue, completedToday, upcomingToday } }`
- Ubicación: `app/api/aperture/stats/route.ts`
2. **Implementar autenticación para Aperture** - ~2-3 horas
- Integración con Supabase Auth para roles admin/manager/staff
- Protección de rutas de Aperture (middleware)
- Session management
- Página login ya existe en `/app/aperture/login/page.tsx`, needs Supabase Auth integration
2. **Implementar autenticación para Aperture** - COMPLETADO
- Integración con Supabase Auth para roles admin/manager/staff
- Protección de rutas de Aperture (middleware creado)
- Session management con AuthProvider existente
- Página login ya existe en `/app/aperture/login/page.tsx`
3. **Implementar reseteo semanal de invitaciones** - ~2-3 horas
- Script/Edge Function que se ejecuta cada Lunes 00:00 UTC