booking capacity check for time slots

This commit is contained in:
Asya Vee
2025-08-27 02:08:23 +04:00
parent c0647fe512
commit 459289df2d
11 changed files with 255 additions and 13 deletions

View File

@@ -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 [];
}
},
};