Files
AnchorOS/app/api/kiosk/resources/available/route.ts
Marco Gallegos 583a25a6f6 feat: implement customer registration flow and business hours system
Major changes:
- Add customer registration with email/phone lookup (app/booking/registro)
- Add customers API endpoint (app/api/customers/route)
- Implement business hours for locations (mon-fri 10-7, sat 10-6, sun closed)
- Fix availability function type casting issues
- Add business hours utilities (lib/utils/business-hours.ts)
- Update Location type to include business_hours JSONB
- Add mock payment component for testing
- Remove Supabase auth from booking flow
- Fix /cita redirect path in booking flow

Database migrations:
- Add category column to services table
- Add business_hours JSONB column to locations table
- Fix availability functions with proper type casting
- Update get_detailed_availability to use business_hours

Features:
- Customer lookup by email or phone
- Auto-redirect to registration if customer not found
- Pre-fill customer data if exists
- Business hours per day of week
- Location-specific opening/closing times
2026-01-17 00:29:49 -06:00

102 lines
2.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server'
import { supabaseAdmin } from '@/lib/supabase/admin'
async function validateKiosk(request: NextRequest) {
const apiKey = request.headers.get('x-kiosk-api-key')
if (!apiKey) {
return null
}
const { data: kiosk } = await supabaseAdmin
.from('kiosks')
.select('id, location_id, is_active')
.eq('api_key', apiKey)
.eq('is_active', true)
.single()
return kiosk
}
/**
* @description Retrieves available resources for kiosk, filtered by time and service
*/
export async function GET(request: NextRequest) {
try {
const kiosk = await validateKiosk(request)
if (!kiosk) {
return NextResponse.json(
{ error: 'Unauthorized' },
{ status: 401 }
)
}
const { searchParams } = new URL(request.url)
const start_time = searchParams.get('start_time')
const end_time = searchParams.get('end_time')
const service_id = searchParams.get('service_id')
if (!start_time || !end_time) {
return NextResponse.json(
{ error: 'start_time and end_time are required' },
{ status: 400 }
)
}
const startTime = new Date(start_time)
const endTime = new Date(end_time)
if (isNaN(startTime.getTime()) || isNaN(endTime.getTime())) {
return NextResponse.json(
{ error: 'Invalid date format' },
{ status: 400 }
)
}
let resourceQuery = supabaseAdmin
.rpc('get_available_resources_with_priority', {
p_location_id: kiosk.location_id,
p_start_time: startTime.toISOString(),
p_end_time: endTime.toISOString()
})
const { data: resources, error } = await resourceQuery
if (error) {
return NextResponse.json(
{ error: error.message },
{ status: 400 }
)
}
let availableResources = resources || []
if (service_id) {
const { data: service } = await supabaseAdmin
.from('services')
.select('requires_dual_artist')
.eq('id', service_id)
.single()
if (service?.requires_dual_artist) {
availableResources = availableResources.filter((r: any) => r.resource_type === 'room')
}
}
return NextResponse.json({
location_id: kiosk.location_id,
start_time: startTime.toISOString(),
end_time: endTime.toISOString(),
resources: availableResources,
total_available: availableResources.length
})
} catch (error) {
console.error('Kiosk resources available error:', error)
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
)
}
}