mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 18:24:31 +00:00
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
93 lines
2.2 KiB
TypeScript
93 lines
2.2 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 Confirms a pending booking by short ID for kiosk
|
|
*/
|
|
export async function POST(
|
|
request: NextRequest,
|
|
{ params }: { params: { shortId: string } }
|
|
) {
|
|
try {
|
|
const kiosk = await validateKiosk(request)
|
|
|
|
if (!kiosk) {
|
|
return NextResponse.json(
|
|
{ error: 'Unauthorized' },
|
|
{ status: 401 }
|
|
)
|
|
}
|
|
|
|
const shortId = params.shortId
|
|
|
|
const { data: booking, error: fetchError } = await supabaseAdmin
|
|
.from('bookings')
|
|
.select('id, status, location_id')
|
|
.eq('short_id', shortId)
|
|
.single()
|
|
|
|
if (fetchError || !booking) {
|
|
return NextResponse.json(
|
|
{ error: 'Booking not found' },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
|
|
if (booking.location_id !== kiosk.location_id) {
|
|
return NextResponse.json(
|
|
{ error: 'Booking not found in kiosk location' },
|
|
{ status: 404 }
|
|
)
|
|
}
|
|
|
|
if (booking.status !== 'pending') {
|
|
return NextResponse.json(
|
|
{ error: 'Booking is not in pending status' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
const { data: updatedBooking, error: updateError } = await supabaseAdmin
|
|
.from('bookings')
|
|
.update({ status: 'confirmed' })
|
|
.eq('id', booking.id)
|
|
.select('id, short_id, status, start_time_utc, end_time_utc')
|
|
.single()
|
|
|
|
if (updateError || !updatedBooking) {
|
|
return NextResponse.json(
|
|
{ error: updateError?.message || 'Failed to confirm booking' },
|
|
{ status: 400 }
|
|
)
|
|
}
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
booking: updatedBooking
|
|
})
|
|
} catch (error) {
|
|
console.error('Kiosk booking confirm error:', error)
|
|
return NextResponse.json(
|
|
{ error: 'Internal server error' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
}
|