BoardService
Board and page CRUD operations
BoardService is the primary domain service for board and page management. It wraps BoardStorage calls with event logging.
Constructor
Injected automatically when using BoardModule.register().
@Injectable()
class BoardService {
constructor(
private readonly storage: BoardStorage,
private readonly eventLog: EventLogStorage,
) {}
}Board Operations
createBoard
Creates a new board with a default first page ("Page 1") and logs a boardUpdated event.
async createBoard(data: CreateBoardInput): Promise<Board>;interface CreateBoardInput {
name: string;
ownerId: string;
sessionType?: 'ephemeral' | 'persistent'; // default: 'persistent'
}getBoard
Retrieves a board by ID. Throws if not found.
async getBoard(id: string): Promise<Board>;listBoards
Lists non-archived boards owned by a user.
async listBoards(userId: string): Promise<Board[]>;updateBoard
Updates board properties and logs a boardUpdated event.
async updateBoard(id: string, data: Partial<Board>, userId: string): Promise<Board>;archiveBoard
Marks a board as archived and logs a boardUpdated event.
async archiveBoard(id: string, userId: string): Promise<void>;deleteBoard
Permanently deletes a board and all associated data.
async deleteBoard(id: string): Promise<void>;Page Operations
addPage
Adds a new page to a board. Auto-names as "Page N" if no name is provided.
async addPage(boardId: string, data?: CreatePageInput, userId?: string): Promise<Page>;interface CreatePageInput {
name?: string;
order: number;
}getPages
Lists all pages for a board, sorted by order.
async getPages(boardId: string): Promise<Page[]>;reorderPages
Reorders pages by providing the page IDs in the desired order.
async reorderPages(boardId: string, pageIds: string[], userId?: string): Promise<void>;deletePage
Deletes a page and logs a pageRemoved event.
async deletePage(pageId: string, boardId: string, userId?: string): Promise<void>;getPageElements
Returns all elements on a page.
async getPageElements(pageId: string): Promise<Element[]>;Usage Example
import { Controller, Post, Get, Body, Param } from '@nestjs/common';
import { BoardService } from '@hfu.digital/boardkit-nestjs';
@Controller('boards')
export class MyBoardController {
constructor(private readonly boardService: BoardService) {}
@Post()
async create(@Body() body: { name: string; ownerId: string }) {
return this.boardService.createBoard(body);
}
@Get(':id/pages')
async getPages(@Param('id') boardId: string) {
return this.boardService.getPages(boardId);
}
}