import { BoardService } from '../services/boardService.js'; import { KanbanService } from '../services/kanbanService.js'; export class BoardController { /** * POST /api/boards * Create a new board with rate-limiting. */ static async createBoard(req, res) { try { const { title } = req.body; const result = await BoardService.createBoard(title); res.status(201).json(result); } catch (error) { console.error('Error creating board:', error); res.status(500).json({ error: 'Failed to create board' }); } } /** * GET /api/boards/:id * Fetch board data using authorization key. */ static async getBoard(req, res) { try { const { boardId, role } = req.boardAuth; const board = await BoardService.getBoardDetails(boardId, role); if (!board) { res.status(404).json({ error: 'Board not found' }); return; } res.json(board); } catch (error) { console.error('Error getting board:', error); res.status(500).json({ error: 'Failed to fetch board' }); } } /** * GET /api/boards/:id/activity * Fetch recent activity / movement logs for board. */ static async getBoardActivity(req, res) { try { const { boardId } = req.boardAuth; const limit = parseInt(req.query.limit, 10) || 50; const logs = await KanbanService.getBoardActivityLogs(boardId, limit); res.json(logs); } catch (error) { console.error('Error getting board activity:', error); res.status(500).json({ error: 'Failed to fetch board activity logs' }); } } /** * GET /api/boards/:id/tickets/:ticketId/activity * Fetch movement logs for specific ticket. */ static async getTicketActivity(req, res) { try { const { ticketId } = req.params; const limit = parseInt(req.query.limit, 10) || 30; const logs = await KanbanService.getTicketActivityLogs(ticketId, limit); res.json(logs); } catch (error) { console.error('Error getting ticket activity:', error); res.status(500).json({ error: 'Failed to fetch ticket activity logs' }); } } /** * POST /api/boards/:id/rotate-member-key * Rotate member key (Admin only). */ static async rotateMemberKey(req, res) { try { const { boardId } = req.boardAuth; const result = await BoardService.rotateMemberKey(boardId); res.json(result); } catch (error) { console.error('Error rotating member key:', error); res.status(500).json({ error: 'Failed to rotate member key' }); } } /** * DELETE /api/boards/:id * Delete board (Admin only). */ static async deleteBoard(req, res) { try { const { boardId } = req.boardAuth; await BoardService.deleteBoard(boardId); res.json({ success: true, message: 'Board deleted successfully' }); } catch (error) { console.error('Error deleting board:', error); res.status(500).json({ error: 'Failed to delete board' }); } } /** * PATCH /api/boards/:id * Update board title (Admin only). */ static async updateBoard(req, res) { try { const { boardId } = req.boardAuth; const { title } = req.body; if (!title || !title.trim()) { res.status(400).json({ error: 'Title is required' }); return; } await BoardService.updateBoard(boardId, { title }); res.json({ success: true, title: title.trim() }); } catch (error) { console.error('Error updating board:', error); res.status(500).json({ error: 'Failed to update board title' }); } } }