backend: Remove room preferences controller and related methods from storage service
This commit is contained in:
parent
a17bcd5771
commit
814f75c4a1
@ -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 });
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@ -121,55 +121,6 @@ export class MeetStorageService<G extends GlobalPreferences = GlobalPreferences,
|
|||||||
return this.storageProvider.deleteMeetRoom(roomId);
|
return this.storageProvider.deleteMeetRoom(roomId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: REMOVE THIS METHOD
|
|
||||||
async getOpenViduRoomPreferences(roomId: string): Promise<MeetRoomPreferences> {
|
|
||||||
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<GlobalPreferences>}
|
|
||||||
*/
|
|
||||||
async updateOpenViduRoomPreferences(roomId: string, roomPreferences: MeetRoomPreferences): Promise<R> {
|
|
||||||
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 the default global preferences.
|
||||||
* @returns {G}
|
* @returns {G}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user