My App
RoomKitBackend

AvailabilityService

Search for available rooms and find next open slots

Overview

AvailabilityService provides compound room availability searches with scoring and a forward-scanning slot finder. It checks overlapping bookings, blackout windows, and operating hours.

import { AvailabilityService } from '@roomkit/nestjs';

Methods

Search for available rooms matching a set of filters. Results are scored by capacity fit and equipment match, and returned with cursor-based pagination.

async search(
    filters: AvailabilityFilter,
    pagination: Pagination,
): Promise<AvailabilityResult>
ParameterTypeDescription
filtersAvailabilityFilterCompound search filters
paginationPaginationCursor-based pagination options

How it works:

  1. Filters rooms by capacity (seated, exam, or standing), equipment, accessibility, and location scope
  2. Checks each candidate for overlapping bookings and blackout windows in the requested time range
  3. Scores results by capacity fit and equipment match
  4. Returns paginated results sorted by score
const result = await availabilityService.search(
    {
        timeRange: {
            startsAt: new Date('2026-03-02T14:00:00'),
            endsAt: new Date('2026-03-02T16:00:00'),
        },
        minCapacity: 20,
        capacityType: 'seated',
        requiredEquipment: ['projector', 'whiteboard'],
        requiredAccessibility: ['wheelchair'],
        locationScope: 'building-north',
    },
    { cursor: null, limit: 10 },
);

for (const room of result.items) {
    console.log(room.id, room.score);
}

findNextAvailable

Scan forward from a given time to find the next available slots for a specific room. Checks bookings, blackout windows, and operating hours.

async findNextAvailable(
    roomId: string,
    after: Date,
    duration: number,
    limit: number,
): Promise<TimeSlot[]>
ParameterTypeDescription
roomIdstringRoom ID to scan
afterDateStart scanning from this time
durationnumberRequired slot duration in minutes
limitnumberMaximum number of slots to return

Scans forward in 30-minute increments for up to 14 days. Returns an array of TimeSlot objects representing available windows.

const slots = await availabilityService.findNextAvailable(
    'room-a1',
    new Date('2026-03-02T09:00:00'),
    60, // 60-minute slot
    3,  // return up to 3 slots
);

for (const slot of slots) {
    console.log(`${slot.startsAt} – ${slot.endsAt}`);
}

Throws RoomNotFoundError if the room does not exist.

AvailabilityFilter

interface AvailabilityFilter {
    timeRange: TimeRange;
    minCapacity?: number;
    capacityType?: 'seated' | 'exam' | 'standing';
    requiredEquipment?: string[];
    requiredAccessibility?: string[];
    locationScope?: string;
    excludeRoomIds?: string[];
}
FieldTypeDescription
timeRangeTimeRangeRequired time range to check availability for
minCapacitynumberMinimum room capacity
capacityType'seated' | 'exam' | 'standing'Which capacity metric to filter by
requiredEquipmentstring[]Equipment the room must have
requiredAccessibilitystring[]Accessibility features the room must have
locationScopestringLocation node ID to scope the search within
excludeRoomIdsstring[]Room IDs to exclude from results

On this page