Module Setup
Configure and register the RoomKitModule
Overview
RoomKitModule is a NestJS dynamic module. Call register() with your storage adapters, priority tiers, feature flags, and optional event handlers.
import { RoomKitModule } from '@roomkit/nestjs';RoomKitModule.register()
Using PrismaRoomKitAdapter
The simplest setup uses the composite PrismaRoomKitAdapter which provides all storage interfaces from a single Prisma client.
import { Module } from '@nestjs/common';
import { RoomKitModule, PrismaRoomKitAdapter } from '@roomkit/nestjs';
import { PrismaService } from './prisma.service';
@Module({
imports: [
RoomKitModule.register({
storage: new PrismaRoomKitAdapter(prisma),
priorities: [
{ name: 'emergency', weight: 100 },
{ name: 'academic', weight: 80 },
{ name: 'administrative', weight: 60 },
{ name: 'student', weight: 40 },
{ name: 'external', weight: 20 },
],
features: {
exams: true,
bulkOperations: true,
},
}),
],
})
export class AppModule {}Using Individual Storage Adapters
For custom or mixed storage backends, pass each adapter individually.
import { Module } from '@nestjs/common';
import {
RoomKitModule,
PrismaLocationAdapter,
PrismaRoomAdapter,
PrismaBookingAdapter,
PrismaRecurrenceAdapter,
PrismaBlackoutAdapter,
PrismaConflictAdapter,
PrismaConfigAdapter,
PrismaAuditAdapter,
PrismaPriorityAdapter,
} from '@roomkit/nestjs';
@Module({
imports: [
RoomKitModule.register({
storage: {
location: new PrismaLocationAdapter(prisma),
room: new PrismaRoomAdapter(prisma),
booking: new PrismaBookingAdapter(prisma),
recurrence: new PrismaRecurrenceAdapter(prisma),
blackout: new PrismaBlackoutAdapter(prisma),
conflict: new PrismaConflictAdapter(prisma),
config: new PrismaConfigAdapter(prisma),
audit: new PrismaAuditAdapter(prisma),
priority: new PrismaPriorityAdapter(prisma),
// Optional adapters — only needed when the feature is enabled
// exam: new PrismaExamAdapter(prisma),
// bulkOperation: new PrismaBulkOperationAdapter(prisma),
},
priorities: [
{ name: 'emergency', weight: 100 },
{ name: 'academic', weight: 80 },
{ name: 'standard', weight: 40 },
],
}),
],
})
export class AppModule {}RoomKitModuleOptions
interface RoomKitModuleOptions {
storage:
| PrismaRoomKitAdapter
| {
location: LocationStorage;
room: RoomStorage;
booking: BookingStorage;
recurrence: RecurrenceStorage;
blackout: BlackoutStorage;
conflict: ConflictStorage;
config: ConfigStorage;
audit: AuditStorage;
priority: PriorityStorage;
exam?: ExamStorage;
bulkOperation?: BulkOperationStorage;
};
priorities: { name: string; weight: number }[];
travelTimeMatrix?: Record<string, number>;
features?: {
exams?: boolean;
bulkOperations?: boolean;
};
events?: Partial<Record<RoomKitEventType, (event: RoomKitEvent) => void>>;
}| Option | Type | Required | Description |
|---|---|---|---|
storage | PrismaRoomKitAdapter | StorageMap | Yes | Composite adapter or individual storage instances |
priorities | { name: string; weight: number }[] | Yes | Priority tiers seeded on bootstrap |
travelTimeMatrix | Record<string, number> | No | Campus pair travel times in minutes (e.g., "campusA|campusB": 15) |
features | { exams?: boolean; bulkOperations?: boolean } | No | Enable optional services |
events | Partial<Record<RoomKitEventType, (event: RoomKitEvent) => void>> | No | Event handlers wired on bootstrap |
Travel Time Matrix
The travelTimeMatrix maps pairs of campus identifiers (pipe-separated) to travel time in minutes. Keys are order-independent — "campusA|campusB" and "campusB|campusA" are equivalent.
RoomKitModule.register({
// ...storage and priorities
travelTimeMatrix: {
'north|south': 25,
'north|downtown': 40,
'south|downtown': 15,
},
})Event Handlers
Wire handlers to domain events at registration time. Handlers are bound during module bootstrap.
RoomKitModule.register({
// ...storage and priorities
events: {
BookingRequested: (event) => notificationService.sendConfirmationEmail(event),
BookingCancelled: (event) => calendarService.removeCalendarEntry(event),
BookingConfirmed: (event) => calendarService.createCalendarEntry(event),
},
})Injection Tokens
| Token | Type | Description |
|---|---|---|
ROOMKIT_OPTIONS | RoomKitModuleOptions | The full options object passed to register() |
TRAVEL_TIME_MATRIX | Record<string, number> | The travel time matrix (empty object if not provided) |
Exported Services
The module exports the following injectable services:
Core Services:
BookingServiceAvailabilityServiceConflictServiceRecurrenceServiceLocationServiceRoomServiceBlackoutServiceConfigServiceAuditServicePriorityService
Optional Services (when enabled via features):
TravelTimeServiceExamServiceBulkOperationService