mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 19:24:32 +00:00
- Add JSDoc comments to API routes and business logic functions - Update README.md with Phase 2 status and deployment/production notes - Enhance TASKS.md with estimated timelines and dependencies - Create docs/STAFF_TRAINING.md for team onboarding - Create docs/CLIENT_ONBOARDING.md for customer experience - Create docs/OPERATIONAL_PROCEDURES.md for daily operations - Create docs/TROUBLESHOOTING.md for common setup issues - Fix TypeScript errors in hq/page.tsx
92 lines
2.0 KiB
TypeScript
92 lines
2.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server'
|
|
import { supabaseAdmin } from '@/lib/supabase/client'
|
|
|
|
/**
|
|
* @description Fetches bookings with filters for dashboard view
|
|
*/
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url)
|
|
const locationId = searchParams.get('location_id')
|
|
const startDate = searchParams.get('start_date')
|
|
const endDate = searchParams.get('end_date')
|
|
const staffId = searchParams.get('staff_id')
|
|
const status = searchParams.get('status')
|
|
|
|
let query = supabaseAdmin
|
|
.from('bookings')
|
|
.select(`
|
|
id,
|
|
short_id,
|
|
status,
|
|
start_time_utc,
|
|
end_time_utc,
|
|
is_paid,
|
|
created_at,
|
|
customer (
|
|
id,
|
|
first_name,
|
|
last_name,
|
|
email
|
|
),
|
|
service (
|
|
id,
|
|
name,
|
|
duration_minutes,
|
|
base_price
|
|
),
|
|
staff (
|
|
id,
|
|
display_name
|
|
),
|
|
resource (
|
|
id,
|
|
name,
|
|
type
|
|
)
|
|
`)
|
|
.order('start_time_utc', { ascending: true })
|
|
|
|
if (locationId) {
|
|
query = query.eq('location_id', locationId)
|
|
}
|
|
|
|
if (startDate) {
|
|
query = query.gte('start_time_utc', startDate)
|
|
}
|
|
|
|
if (endDate) {
|
|
query = query.lte('end_time_utc', endDate)
|
|
}
|
|
|
|
if (staffId) {
|
|
query = query.eq('staff_id', staffId)
|
|
}
|
|
|
|
if (status) {
|
|
query = query.in('status', status.split(','))
|
|
}
|
|
|
|
const { data: bookings, error } = await query
|
|
|
|
if (error) {
|
|
console.error('Aperture dashboard GET error:', error)
|
|
return NextResponse.json(
|
|
{ error: error.message },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
bookings: bookings || []
|
|
})
|
|
} catch (error) {
|
|
console.error('Aperture dashboard GET error:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Internal server error' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|