RoomService
Manage rooms, equipment, accessibility, and partitions
Overview
RoomService provides full CRUD for rooms including equipment tags, accessibility attributes, and parent/child partition relationships. It validates location nodes and enforces structural integrity of partition trees.
import { RoomService } from '@roomkit/nestjs';Methods
create
Create a new room. Validates the DTO and verifies that the referenced locationNodeId is of type ROOM.
async create(dto: CreateRoomDto): Promise<Room>| Parameter | Type | Description |
|---|---|---|
dto | CreateRoomDto | Room creation data including name, capacity, and locationNodeId |
const room = await roomService.create({
name: 'Lecture Hall A',
locationNodeId: 'node-room-a1',
seatedCapacity: 120,
examCapacity: 60,
standingCapacity: 200,
isActive: true,
});Throws RoomKitError with code INVALID_LOCATION_TYPE if the location node is not of type ROOM.
findById
Find a room by its ID.
async findById(id: string): Promise<Room | null>| Parameter | Type | Description |
|---|---|---|
id | string | The room ID |
Returns null if no room is found.
const room = await roomService.findById('room-a1');findByFilter
Find rooms matching a compound filter.
async findByFilter(filter: RoomFilterDto): Promise<Room[]>| Parameter | Type | Description |
|---|---|---|
filter | RoomFilterDto | Compound filter criteria |
Filter fields:
| Field | Type | Description |
|---|---|---|
minCapacity | number | Minimum required capacity |
capacityType | 'seated' | 'exam' | 'standing' | Which capacity field to check against |
equipment | string[] | Required equipment tags (all must match) |
accessibility | string[] | Required accessibility attributes (all must match) |
locationScope | string | Limit search to descendants of this location node |
isActive | boolean | Filter by active/inactive status |
const rooms = await roomService.findByFilter({
minCapacity: 50,
capacityType: 'seated',
equipment: ['projector', 'whiteboard'],
accessibility: ['wheelchair'],
locationScope: 'building-science',
isActive: true,
});getPartitionTree
Get the partition tree for a room, including all parent/child relationships.
async getPartitionTree(roomId: string): Promise<RoomPartition[]>| Parameter | Type | Description |
|---|---|---|
roomId | string | The room ID to get partition tree for |
const partitions = await roomService.getPartitionTree('room-a1');
// Returns parent/child relationships for the roomThrows RoomNotFoundError if the room does not exist.
getWithEquipment
Get a room with its equipment tags and accessibility attributes loaded.
async getWithEquipment(id: string): Promise<(Room & { equipment: RoomEquipment[]; accessibility: RoomAccessibility[] }) | null>| Parameter | Type | Description |
|---|---|---|
id | string | The room ID |
Returns null if no room is found.
const room = await roomService.getWithEquipment('room-a1');
if (room) {
console.log('Equipment:', room.equipment.map(e => e.tag));
console.log('Accessibility:', room.accessibility.map(a => a.attribute));
}getEffectiveOperatingHours
Get the effective operating hours for a room by walking up the location hierarchy from the room's node to the root. Returns the most specific hours found.
async getEffectiveOperatingHours(roomId: string): Promise<OperatingHours[]>| Parameter | Type | Description |
|---|---|---|
roomId | string | The room ID |
const hours = await roomService.getEffectiveOperatingHours('room-a1');
// Returns hours from the nearest ancestor that defines themThrows RoomNotFoundError if the room does not exist.
addEquipment
Add an equipment tag to a room.
async addEquipment(roomId: string, tag: string): Promise<RoomEquipment>| Parameter | Type | Description |
|---|---|---|
roomId | string | The room ID |
tag | string | Equipment tag to add (e.g., 'projector', 'whiteboard') |
const equipment = await roomService.addEquipment('room-a1', 'projector');Throws RoomNotFoundError if the room does not exist.
removeEquipment
Remove an equipment tag from a room.
async removeEquipment(roomId: string, tag: string): Promise<void>| Parameter | Type | Description |
|---|---|---|
roomId | string | The room ID |
tag | string | Equipment tag to remove |
await roomService.removeEquipment('room-a1', 'projector');Throws RoomNotFoundError if the room does not exist.
addAccessibility
Add an accessibility attribute to a room.
async addAccessibility(roomId: string, attribute: string): Promise<RoomAccessibility>| Parameter | Type | Description |
|---|---|---|
roomId | string | The room ID |
attribute | string | Accessibility attribute to add (e.g., 'wheelchair', 'hearing_loop') |
const attr = await roomService.addAccessibility('room-a1', 'wheelchair');Throws RoomNotFoundError if the room does not exist.
removeAccessibility
Remove an accessibility attribute from a room.
async removeAccessibility(roomId: string, attribute: string): Promise<void>| Parameter | Type | Description |
|---|---|---|
roomId | string | The room ID |
attribute | string | Accessibility attribute to remove |
await roomService.removeAccessibility('room-a1', 'wheelchair');Throws RoomNotFoundError if the room does not exist.
createPartition
Create a parent/child partition relationship between two rooms. Validates that both rooms exist and checks for circular references.
async createPartition(parentRoomId: string, childRoomId: string): Promise<RoomPartition>| Parameter | Type | Description |
|---|---|---|
parentRoomId | string | The parent room ID |
childRoomId | string | The child room ID |
const partition = await roomService.createPartition('room-hall-a', 'room-hall-a1');Throws RoomNotFoundError if either room does not exist.
Throws RoomKitError with code CIRCULAR_PARTITION if the relationship would create a circular reference.
deletePartition
Delete a partition relationship.
async deletePartition(id: string): Promise<void>| Parameter | Type | Description |
|---|---|---|
id | string | The partition ID |
await roomService.deletePartition('partition-1');