diff --git a/backend/src/controllers/global-preferences/room-preferences.controller.ts b/backend/src/controllers/global-preferences/room-preferences.controller.ts deleted file mode 100644 index d3868d3..0000000 --- a/backend/src/controllers/global-preferences/room-preferences.controller.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { container } from '../../config/dependency-injector.config.js'; -import { Request, Response } from 'express'; -import { LoggerService } from '../../services/logger.service.js'; -import { MeetStorageService } from '../../services/storage/index.js'; -import { OpenViduMeetError } from '../../models/error.model.js'; - -export const updateRoomPreferences = async (req: Request, res: Response) => { - const logger = container.get(LoggerService); - - logger.verbose(`Updating room preferences: ${JSON.stringify(req.body)}`); - const { roomId, roomPreferences } = req.body; - - try { - const preferenceService = container.get(MeetStorageService); - preferenceService.validateRoomPreferences(roomPreferences); - - const savedPreferences = await preferenceService.updateOpenViduRoomPreferences(roomId, roomPreferences); - - return res - .status(200) - .json({ message: 'Room preferences updated successfully.', preferences: savedPreferences }); - } catch (error) { - if (error instanceof OpenViduMeetError) { - logger.error(`Error saving room preferences: ${error.message}`); - return res.status(error.statusCode).json({ name: error.name, message: error.message }); - } - - logger.error('Error saving room preferences:' + error); - return res.status(500).json({ message: 'Error saving room preferences', error }); - } -}; - -export const getRoomPreferences = async (req: Request, res: Response) => { - const logger = container.get(LoggerService); - - try { - const { roomId } = req.params; - const preferenceService = container.get(MeetStorageService); - const preferences = await preferenceService.getOpenViduRoomPreferences(roomId); - - if (!preferences) { - return res.status(404).json({ message: 'Room preferences not found' }); - } - - return res.status(200).json(preferences); - } catch (error) { - if (error instanceof OpenViduMeetError) { - logger.error(`Error getting room preferences: ${error.message}`); - return res.status(error.statusCode).json({ name: error.name, message: error.message }); - } - - logger.error('Error getting room preferences:' + error); - return res.status(500).json({ message: 'Error fetching room preferences from database', error }); - } -}; diff --git a/backend/src/services/storage/storage.service.ts b/backend/src/services/storage/storage.service.ts index fa29ff7..c6b12d9 100644 --- a/backend/src/services/storage/storage.service.ts +++ b/backend/src/services/storage/storage.service.ts @@ -121,55 +121,6 @@ export class MeetStorageService { - const openviduRoom = await this.getMeetRoom(roomId); - - if (!openviduRoom.preferences) { - throw new Error('Room preferences not found'); - } - - return openviduRoom.preferences; - } - - /** - * TODO: Move validation to the controller layer - * Updates room preferences in storage. - * @param {RoomPreferences} roomPreferences - * @returns {Promise} - */ - async updateOpenViduRoomPreferences(roomId: string, roomPreferences: MeetRoomPreferences): Promise { - this.validateRoomPreferences(roomPreferences); - - const openviduRoom = await this.getMeetRoom(roomId); - openviduRoom.preferences = roomPreferences; - return this.saveMeetRoom(openviduRoom); - } - - /** - * Validates the room preferences. - * @param {RoomPreferences} preferences - */ - validateRoomPreferences(preferences: MeetRoomPreferences) { - const { recordingPreferences, chatPreferences, virtualBackgroundPreferences } = preferences; - - if (!recordingPreferences || !chatPreferences || !virtualBackgroundPreferences) { - throw new Error('All room preferences must be provided'); - } - - if (typeof preferences.recordingPreferences.enabled !== 'boolean') { - throw new Error('Invalid value for recordingPreferences.enabled'); - } - - if (typeof preferences.chatPreferences.enabled !== 'boolean') { - throw new Error('Invalid value for chatPreferences.enabled'); - } - - if (typeof preferences.virtualBackgroundPreferences.enabled !== 'boolean') { - throw new Error('Invalid value for virtualBackgroundPreferences.enabled'); - } - } - /** * Returns the default global preferences. * @returns {G}