Skip to content
Snippets Groups Projects
Commit bb173950 authored by MonaS8's avatar MonaS8
Browse files

add comments and small changes for roles and modes

parent d7d3e86d
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ export class ModeService {
@InjectRepository(Mode)
private readonly modeRepository: EntityRepository<Mode>) {}
async createMode(roomSession: RoomSession, modeName: string): Promise<Mode> {
async createMode(roomSession: RoomSession, modeName: ModeType): Promise<Mode> {
const mode = new Mode(modeName, roomSession);
await this.em.persistAndFlush(mode);
return mode;
......
......@@ -18,7 +18,7 @@ export class RoleService {
@InjectRepository(Role)
private readonly roleRepository: EntityRepository<Role>) {}
async createRole(roleName: string, roomSessionUser: RoomSessionUser): Promise<Role> {
async createRole(roleName: RoleType, roomSessionUser: RoomSessionUser): Promise<Role> {
const role = new Role(roleName, roomSessionUser);
await this.em.persistAndFlush(role);
return role;
......
......@@ -94,15 +94,14 @@ export class RoomSessionService {
return modeType;
}
private shouldAssignPairProgramming(roomSession: RoomSession): boolean {
const users = roomSession.users.getItems();
private async shouldAssignPairProgramming(roomSession: RoomSession): Promise<boolean> {
const users = await roomSession.users.loadItems();
return users.length === 2;
}
private shouldAssignRoleBasedProgramming(roomSession: RoomSession): boolean {
const users = roomSession.users.getItems();
return users.length > 2;
}
private async shouldAssignRoleBasedProgramming(roomSession: RoomSession): Promise<boolean> {
const users = await roomSession.users.loadItems();
return users.length > 2;
}
}
......@@ -27,20 +27,38 @@ export class RoomSessionUserService {
@InjectRepository(SessionPoints)
private readonly pointsRepository: EntityRepository<SessionPoints>,
@InjectRepository(RoomSessionUser)
private readonly repository: EntityRepository<RoomSessionUser>,
private readonly userRepository: EntityRepository<RoomSessionUser>,
private readonly activitiesService: ActivitiesService,
private readonly roleService: RoleService,
private readonly roomSessionService: RoomSessionService,
) {}
/**
* Adds a new user to a room session.
*
* @param roomSession - The room session to which the user will be added.
* @param userId - The unique identifier of the user to be added.
* @param name - The name of the user to be added.
* @returns A promise that resolves to the newly created `RoomSessionUser` instance.
*/
public async addSessionUser(roomSession: RoomSession, userId: string, name: string): Promise<RoomSessionUser> {
const roomSessionUser = new RoomSessionUser(roomSession, userId, name);
await this.em.persistAndFlush(roomSessionUser);
return roomSessionUser;
}
/**
* Updates the name of a user in a room session. If the user already exists in the session,
* their name is updated. If the user does not exist, a new user is created and added to the session.
*
* @param roomSession - The room session to which the user belongs.
* @param userId - The unique identifier of the user.
* @param name - The new name to assign to the user.
* @returns The updated or newly created RoomSessionUser instance.
* @throws An error if the operation fails during persistence.
*/
async updateSessionUserName(roomSession: RoomSession, userId: string, name:string) {
let user = await this.repository.findOne({ roomSession, userId });
let user = await this.userRepository.findOne({ roomSession, userId });
if (user) {
user.name = name;
} else {
......@@ -88,33 +106,77 @@ export class RoomSessionUserService {
};
}
/**
* Assigns roles to a given RoomSessionUser based on their points and the session's total points.
*
* This method evaluates the user's points in the context of the session and determines
* which roles should be assigned to them. The roles are then created and associated
* with the user in the system.
*
* @param roomSessionUser - The RoomSessionUser entity for which roles are to be assigned.
* @returns A promise that resolves to an array of assigned RoleType values.
*/
public async assignRole(roomSessionUser: RoomSessionUser): Promise<RoleType[]> {
const points = await this.getPointsByRoomSessionUser(roomSessionUser.id);
const sessionPoints = await this.roomSessionService.getAllPointsBySession(roomSessionUser.roomSession.id);
let roleTypes: RoleType[] = [];
if (this.shouldAssignModerator(points)) {
if (this.shouldAssignModerator(points, sessionPoints)) {
roleTypes.push(RoleType.MODERATOR);
}
if (this.shouldAssignNoteTaker(points, sessionPoints)) {
roleTypes.push(RoleType.NOTETAKER);
}
if (this.shouldAssignGhost(points)) {
roleTypes.push(RoleType.GHOST);
}
for (let role of roleTypes) {
await this.roleService.createRole(role, roomSessionUser);
}
return roleTypes;
}
private shouldAssignModerator(points: RoomSessionUserPointsResponseDto): boolean {
return points.allPoints.audioPoints > 10 && points.allPoints.videoPoints > 10;
/**
* Determines whether a user should be assigned as a moderator based on their audio points
* relative to the total session audio points.
*
* @param points - The user's points data, including audio points.
* @param sessionPoints - The session's total points data, including audio points.
* @returns A promise that resolves to a boolean indicating whether the user should be assigned as a moderator.
*/
private async shouldAssignModerator(points: RoomSessionUserPointsResponseDto, sessionPoints: RoomSessionPointsRequestDto): Promise<boolean> {
let shouldAssignModerator = false;
if (points.allPoints.audioPoints/sessionPoints.allPoints.audioPoints > 0.5) {
shouldAssignModerator = true;
return shouldAssignModerator;
}
}
private shouldAssignNoteTaker(points: RoomSessionUserPointsResponseDto, sessionPoints: RoomSessionPointsRequestDto): boolean {
/**
* Determines whether a note taker should be assigned based on the user's note points
* relative to the total note points in the session and the number of users in the session.
*
* @param points - An object containing the user's points and session ID.
* @param sessionPoints - An object containing the total points for the session.
* @returns A promise that resolves to a boolean indicating whether a note taker should be assigned.
*/
private async shouldAssignNoteTaker(points: RoomSessionUserPointsResponseDto, sessionPoints: RoomSessionPointsRequestDto): Promise<boolean> {
let shouldAssignNoteTaker = false;
const userCount = 2; //ToDo: wie viele User sind in der Session?
const userCount = await this.userRepository.count({ roomSession: points.sessionId });
if (points.allPoints.notePoints/sessionPoints.allPoints.notePoints > 1/userCount) {
shouldAssignNoteTaker = true;
return shouldAssignNoteTaker;
//ToDo: ab wann wird der NoteTaker zugewiesen? mind. 50% der NotePoints im Vergleich zu allen NotePoints? oder wer am meisten NotePoints hat? etc.
}
}
/**
* Determines whether a ghost should be assigned to a user based on their activity points.
*
* @param points - An object containing the user's activity points, including browser and whiteboard points.
* @returns A promise that resolves to `true` if both browserPoints and whiteboardPoints exceed 10, otherwise `false`.
*/
public async shouldAssignGhost(points: RoomSessionUserPointsResponseDto): Promise<boolean> {
return points.allPoints.browserPoints > 10 && points.allPoints.whiteboardPoints > 10;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment