feat: Implementar base de Aperture (aperture.anchor23.mx)

**Aperture - Backend para staff/manager/admin:**
- Crear página principal de admin (/aperture)
  - Dashboard con estadísticas del día (citas, ingresos, pendientes)
  - Navegación por tabs (Dashboard, Staff, Recursos, Reportes)
  - Diseño limpio con métricas y cards

- Crear APIs administrativas:
  - /api/aperture/staff - Staff disponible por ubicación
  - /api/aperture/staff/schedule - CRUD de horarios de staff
    - GET: Listar horarios con filtros
    - POST: Crear bloqueo de horario
    - DELETE: Eliminar horario
  - /api/aperture/resources - Recursos por ubicación
  - /api/aperture/dashboard - Bookings por fecha y staff

**The Boutique - Mejoras:**
- Página de confirmación por código (/booking/confirmacion)
  - Verificación por short_id
  - Detalles completos de cita
  - Información sobre políticas
- Layout personalizado con navbar específico

**TASKS.md - Actualización:**
- Aperture marcado como 'En Progreso' con APIs implementadas
- The Boutique actualizado con página de confirmación
- Reorganización de tareas prioritarias
- Estado del proyecto actualizado (Fase 2: 30%)

**Arquitectura:**
- Separación clara: anchor23.mx (marketing), booking (cliente), aperture (operaciones)
- APIs RESTful para gestión administrativa
- Dashboard responsive con métricas operativas
This commit is contained in:
Marco Gallegos
2026-01-16 16:32:43 -06:00
parent 9bb0caaecf
commit aeb11e1e96
6 changed files with 631 additions and 27 deletions

View File

@@ -0,0 +1,41 @@
import { NextRequest, NextResponse } from 'next/server'
import { supabaseAdmin } from '@/lib/supabase/client'
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const locationId = searchParams.get('location_id')
const date = searchParams.get('date')
if (!locationId || !date) {
return NextResponse.json(
{ error: 'Missing required parameters: location_id, date' },
{ status: 400 }
)
}
const { data: staff, error: staffError } = await supabaseAdmin.rpc('get_available_staff', {
p_location_id: locationId,
p_start_time_utc: `${date}T00:00:00Z`,
p_end_time_utc: `${date}T23:59:59Z`
})
if (staffError) {
return NextResponse.json(
{ error: staffError.message },
{ status: 500 }
)
}
return NextResponse.json({
success: true,
staff: staff || []
})
} catch (error) {
console.error('Aperture staff GET error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}

View File

@@ -0,0 +1,181 @@
import { NextRequest, NextResponse } from 'next/server'
import { supabaseAdmin } from '@/lib/supabase/client'
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const locationId = searchParams.get('location_id')
const staffId = searchParams.get('staff_id')
const startDate = searchParams.get('start_date')
const endDate = searchParams.get('end_date')
let query = supabaseAdmin
.from('staff_availability')
.select('*')
.order('date', { ascending: true })
if (locationId) {
const locationStaff = await supabaseAdmin
.from('staff')
.select('id, display_name')
.eq('location_id', locationId)
.eq('is_active', true)
query = query.in('staff_id', locationStaff.map(s => s.id))
}
if (staffId) {
query = query.eq('staff_id', staffId)
}
if (startDate) {
query = query.gte('date', startDate)
}
if (endDate) {
query = query.lte('date', endDate)
}
const { data: availability, error } = await query
if (error) {
return NextResponse.json(
{ error: error.message },
{ status: 500 }
)
}
return NextResponse.json({
success: true,
availability: availability || []
})
} catch (error) {
console.error('Aperture staff schedule GET error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}
export async function POST(request: NextRequest) {
try {
const body = await request.json()
const {
staff_id,
date,
start_time,
end_time,
is_available,
reason
} = body
if (!staff_id || !date || !start_time || !end_time) {
return NextResponse.json(
{ error: 'Missing required fields: staff_id, date, start_time, end_time' },
{ status: 400 }
)
}
const { data: existing, error: checkError } = await supabaseAdmin
.from('staff_availability')
.select('*')
.eq('staff_id', staff_id)
.eq('date', date)
.single()
if (existing && !is_available) {
await supabaseAdmin
.from('staff_availability')
.update({
start_time,
end_time,
is_available,
reason
})
.eq('staff_id', staff_id)
.eq('date', date)
.single()
return NextResponse.json({
success: true,
availability: existing
})
}
if (checkError) {
return NextResponse.json(
{ error: checkError.message },
{ status: 500 }
)
}
const { data: availability, error } = await supabaseAdmin
.from('staff_availability')
.insert({
staff_id,
date,
start_time,
end_time,
is_available,
reason
})
.select()
.single()
if (error || !availability) {
return NextResponse.json(
{ error: error?.message || 'Failed to create staff availability' },
{ status: 500 }
)
}
return NextResponse.json({
success: true,
availability
}, { status: 201 })
} catch (error) {
console.error('Aperture staff schedule POST error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}
export async function DELETE(request: NextRequest) {
try {
const { searchParams } = new URL(request.url)
const id = searchParams.get('id')
if (!id) {
return NextResponse.json(
{ error: 'Missing required parameter: id' },
{ status: 400 }
)
}
const { error } = await supabaseAdmin
.from('staff_availability')
.delete()
.eq('id', id)
if (error) {
return NextResponse.json(
{ error: error.message },
{ status: 500 }
)
}
return NextResponse.json({
success: true,
message: 'Staff availability deleted successfully'
})
} catch (error) {
console.error('Aperture staff schedule DELETE error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}