booking capacity check for time slots
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import PocketBase from 'pocketbase';
|
||||
import { BookingType, TimeSlot } from '@/types/bookings';
|
||||
import { BookingType, TimeSlot, Booking } from '@/types/bookings';
|
||||
|
||||
// Initialize PocketBase client
|
||||
export const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL || 'http://127.0.0.1:8090');
|
||||
@@ -122,4 +122,26 @@ export const bookingApi = {
|
||||
|
||||
return availableSlotsByDate;
|
||||
},
|
||||
|
||||
// Get all bookings for a specific date filtered by booking type IDs
|
||||
async getBookingsForDate(
|
||||
date: string,
|
||||
bookingTypeIds: string[]
|
||||
): Promise<Booking[]> {
|
||||
try {
|
||||
// Create filter for booking type IDs
|
||||
const bookingTypeFilter = bookingTypeIds.map(id => `booking_type = "${id}"`).join(' || ');
|
||||
|
||||
const bookings = await pb.collection('bookings').getFullList<Booking>({
|
||||
filter: `status = "confirmed" && start_time ~ "${date}" && (${bookingTypeFilter})`,
|
||||
sort: 'start_time'
|
||||
});
|
||||
|
||||
console.log(`Bookings for ${date}:`, bookings);
|
||||
return bookings;
|
||||
} catch (error) {
|
||||
console.error('Error fetching bookings for date:', error);
|
||||
return [];
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user