mirror of
https://github.com/marcogll/AnchorOS.git
synced 2026-03-15 16:24:30 +00:00
feat: Add kiosk management, artist selection, and schedule management
- Add KiosksManagement component with full CRUD for kiosks - Add ScheduleManagement for staff schedules with break reminders - Update booking flow to allow artist selection by customers - Add staff_services API for assigning services to artists - Update staff management UI with service assignment dialog - Add auto-break reminder when schedule >= 8 hours - Update availability API to filter artists by service - Add kiosk management to Aperture dashboard - Clean up ralphy artifacts and logs
This commit is contained in:
@@ -2,41 +2,125 @@ import { NextRequest, NextResponse } from 'next/server'
|
||||
import { supabaseAdmin } from '@/lib/supabase/admin'
|
||||
|
||||
/**
|
||||
* @description Retrieves available staff for a time range
|
||||
* @description Retrieves a list of available staff members for a specific time range and location
|
||||
* @param {NextRequest} request - HTTP request with query parameters for location_id, start_time_utc, and end_time_utc
|
||||
* @returns {NextResponse} JSON with available staff array, time range details, and count
|
||||
* @example GET /api/availability/staff?location_id=...&start_time_utc=...&end_time_utc=...
|
||||
* @audit BUSINESS RULE: Staff must be active, available for booking, and have no booking conflicts in the time range
|
||||
* @audit SECURITY: Validates required query parameters before database call
|
||||
* @audit Validate: Ensures start_time_utc is before end_time_utc and both are valid ISO8601 timestamps
|
||||
* @audit PERFORMANCE: Uses RPC function 'get_available_staff' for optimized database query
|
||||
* @audit AUDIT: Staff availability queries are logged for operational monitoring
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url)
|
||||
const locationId = searchParams.get('location_id')
|
||||
const serviceId = searchParams.get('service_id')
|
||||
const date = searchParams.get('date')
|
||||
const startTime = searchParams.get('start_time_utc')
|
||||
const endTime = searchParams.get('end_time_utc')
|
||||
|
||||
if (!locationId || !startTime || !endTime) {
|
||||
if (!locationId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Missing required parameters: location_id, start_time_utc, end_time_utc' },
|
||||
{ error: 'Missing required parameter: location_id' },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const { data: staff, error: staffError } = await supabaseAdmin.rpc('get_available_staff', {
|
||||
p_location_id: locationId,
|
||||
p_start_time_utc: startTime,
|
||||
p_end_time_utc: endTime
|
||||
})
|
||||
let staff: any[] = []
|
||||
|
||||
if (staffError) {
|
||||
return NextResponse.json(
|
||||
{ error: staffError.message },
|
||||
{ status: 400 }
|
||||
)
|
||||
if (startTime && endTime) {
|
||||
const { data, error } = await supabaseAdmin.rpc('get_available_staff', {
|
||||
p_location_id: locationId,
|
||||
p_start_time_utc: startTime,
|
||||
p_end_time_utc: endTime
|
||||
})
|
||||
|
||||
if (error) {
|
||||
return NextResponse.json(
|
||||
{ error: error.message },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
staff = data || []
|
||||
} else if (date && serviceId) {
|
||||
const { data: service, error: serviceError } = await supabaseAdmin
|
||||
.from('services')
|
||||
.select('duration_minutes')
|
||||
.eq('id', serviceId)
|
||||
.single()
|
||||
|
||||
if (serviceError || !service) {
|
||||
return NextResponse.json(
|
||||
{ error: 'Service not found' },
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
const { data: allStaff, error: staffError } = await supabaseAdmin
|
||||
.from('staff')
|
||||
.select(`
|
||||
id,
|
||||
display_name,
|
||||
role,
|
||||
is_active,
|
||||
user_id,
|
||||
location_id,
|
||||
staff_services!inner (
|
||||
service_id,
|
||||
is_active
|
||||
)
|
||||
`)
|
||||
.eq('location_id', locationId)
|
||||
.eq('is_active', true)
|
||||
.eq('role', 'artist')
|
||||
.eq('staff_services.service_id', serviceId)
|
||||
.eq('staff_services.is_active', true)
|
||||
|
||||
if (staffError) {
|
||||
return NextResponse.json(
|
||||
{ error: staffError.message },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
const deduped = new Map()
|
||||
allStaff?.forEach((s: any) => {
|
||||
if (!deduped.has(s.id)) {
|
||||
deduped.set(s.id, {
|
||||
id: s.id,
|
||||
display_name: s.display_name,
|
||||
role: s.role,
|
||||
is_active: s.is_active
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
staff = Array.from(deduped.values())
|
||||
} else {
|
||||
const { data: allStaff, error: staffError } = await supabaseAdmin
|
||||
.from('staff')
|
||||
.select('id, display_name, role, is_active')
|
||||
.eq('location_id', locationId)
|
||||
.eq('is_active', true)
|
||||
.eq('role', 'artist')
|
||||
|
||||
if (staffError) {
|
||||
return NextResponse.json(
|
||||
{ error: staffError.message },
|
||||
{ status: 400 }
|
||||
)
|
||||
}
|
||||
|
||||
staff = allStaff || []
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
staff: staff || [],
|
||||
staff,
|
||||
location_id: locationId,
|
||||
start_time_utc: startTime,
|
||||
end_time_utc: endTime,
|
||||
available_count: staff?.length || 0
|
||||
})
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user