My App
RoomKitBackend

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>
ParameterTypeDescription
dtoCreateRoomDtoRoom 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>
ParameterTypeDescription
idstringThe 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[]>
ParameterTypeDescription
filterRoomFilterDtoCompound filter criteria

Filter fields:

FieldTypeDescription
minCapacitynumberMinimum required capacity
capacityType'seated' | 'exam' | 'standing'Which capacity field to check against
equipmentstring[]Required equipment tags (all must match)
accessibilitystring[]Required accessibility attributes (all must match)
locationScopestringLimit search to descendants of this location node
isActivebooleanFilter 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[]>
ParameterTypeDescription
roomIdstringThe room ID to get partition tree for
const partitions = await roomService.getPartitionTree('room-a1');
// Returns parent/child relationships for the room

Throws 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>
ParameterTypeDescription
idstringThe 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[]>
ParameterTypeDescription
roomIdstringThe room ID
const hours = await roomService.getEffectiveOperatingHours('room-a1');
// Returns hours from the nearest ancestor that defines them

Throws RoomNotFoundError if the room does not exist.

addEquipment

Add an equipment tag to a room.

async addEquipment(roomId: string, tag: string): Promise<RoomEquipment>
ParameterTypeDescription
roomIdstringThe room ID
tagstringEquipment 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>
ParameterTypeDescription
roomIdstringThe room ID
tagstringEquipment 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>
ParameterTypeDescription
roomIdstringThe room ID
attributestringAccessibility 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>
ParameterTypeDescription
roomIdstringThe room ID
attributestringAccessibility 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>
ParameterTypeDescription
parentRoomIdstringThe parent room ID
childRoomIdstringThe 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>
ParameterTypeDescription
idstringThe partition ID
await roomService.deletePartition('partition-1');

On this page