From ba1ed463053c9238b2efe963727b16cfc06eeb64 Mon Sep 17 00:00:00 2001 From: MonaS8 <schumo62@gmail.com> Date: Fri, 28 Mar 2025 20:45:41 +0100 Subject: [PATCH] update RoleType, error fixing --- src/activities/activities.service.ts | 18 +++++++------- src/channel/channel.service.ts | 2 +- src/points/sessionPoints.entity.ts | 14 +++++------ src/roles/role.service.ts | 11 ++++++--- src/room/roomSessionUser.controller.ts | 21 ++++++++-------- src/room/roomSessionUser.dto.ts | 18 +++++++------- src/room/roomSessionUser.service.ts | 34 +++++++++++++------------- 7 files changed, 62 insertions(+), 56 deletions(-) diff --git a/src/activities/activities.service.ts b/src/activities/activities.service.ts index c6196e1..f1a0db0 100644 --- a/src/activities/activities.service.ts +++ b/src/activities/activities.service.ts @@ -178,15 +178,15 @@ export class ActivitiesService { const pointsArray: SessionPoints[] = []; for (const [user, userActivities] of activitiesByUsers) { - await this.em.removeAndFlush(await this.em.find(SessionPoints, { roomSessionUser: user })); - const points = new SessionPoints( - user, - await this.calculateAudioPoints(userActivities), - await this.calculateVideoPoints(userActivities), - await this.calculateBrowserPoints(userActivities), - await this.calculateWhiteboardPoints(userActivities), - await this.calculateNotePoints(userActivities), - ); + let points = await this.em.findOne(SessionPoints, { roomSessionUser: user }); + if (!points) { + points = new SessionPoints(user); + } + points.audioPoints = await this.calculateAudioPoints(userActivities), + points.videoPoints = await this.calculateVideoPoints(userActivities), + points.browserPoints = await this.calculateBrowserPoints(userActivities), + points.whiteboardPoints = await this.calculateWhiteboardPoints(userActivities), + points.notePoints = await this.calculateNotePoints(userActivities), await this.em.persistAndFlush(points); pointsArray.push(points); diff --git a/src/channel/channel.service.ts b/src/channel/channel.service.ts index 853d74c..aa89dc7 100644 --- a/src/channel/channel.service.ts +++ b/src/channel/channel.service.ts @@ -178,7 +178,7 @@ export class ChannelService { } public async close(channel: Channel) { - await this.rooms.updateWhiteboard(channel.room.id, channel.canvasJSON); + //await this.rooms.updateWhiteboard(channel.room.id, channel.canvasJSON); await this.browsers.closeBrowserContext(channel.id); await this.roomSessionService.closeSession(channel.session); diff --git a/src/points/sessionPoints.entity.ts b/src/points/sessionPoints.entity.ts index 053bbe2..6a3f334 100644 --- a/src/points/sessionPoints.entity.ts +++ b/src/points/sessionPoints.entity.ts @@ -14,7 +14,7 @@ export class SessionPoints { @PrimaryKey() id!: number; - @ManyToOne(() => RoomSessionUser) + @ManyToOne(() => RoomSessionUser, { unique: true }) roomSessionUser!: RoomSessionUser; @Property() @@ -32,12 +32,12 @@ export class SessionPoints { @Property() notePoints: number; - constructor(roomSessionUser: RoomSessionUser, audioPoints: number, videoPoints: number, browserPoints: number, whiteboardPoints: number, notePoints: number) { + constructor(roomSessionUser: RoomSessionUser) { this.roomSessionUser = roomSessionUser; - this.audioPoints = audioPoints; - this.videoPoints = videoPoints; - this.browserPoints = browserPoints; - this.whiteboardPoints = whiteboardPoints; - this.notePoints = notePoints; + this.audioPoints = 0; + this.videoPoints = 0; + this.browserPoints = 0; + this.whiteboardPoints = 0; + this.notePoints = 0; } } \ No newline at end of file diff --git a/src/roles/role.service.ts b/src/roles/role.service.ts index 9448cc2..bfec83f 100644 --- a/src/roles/role.service.ts +++ b/src/roles/role.service.ts @@ -6,9 +6,14 @@ import { RoomSessionUser } from '../room/roomSessionUser.entity'; import { EntityManager } from '@mikro-orm/mysql'; export enum RoleType { - MODERATOR = 'moderator', - NOTETAKER = 'noteTaker', - GHOST = 'ghost', + COORDINATOR = 'COORDINATOR', + DOCUMENTER = 'DOCUMENTER', + CODER_DEBUGGER = 'CODER_DEBUGGER', + VISUALIZER = 'VISUALIZER', + ACTIVE_PARTICIPANT = 'ACTIVE_PARTICIPANT', + OBSERVER = 'OBSERVER', + LURKER = 'LURKER', + DISRUPTOR = 'DISRUPTOR', } @Injectable() diff --git a/src/room/roomSessionUser.controller.ts b/src/room/roomSessionUser.controller.ts index 76e8518..df5bb81 100644 --- a/src/room/roomSessionUser.controller.ts +++ b/src/room/roomSessionUser.controller.ts @@ -8,17 +8,18 @@ export class RoomSessionUserPointsController { constructor( private readonly roomSessionUser: RoomSessionUserService) {} - @UseGuards(AuthGuard) - @Get('/user/:userId') /** * Retrieves the total points for a specific user based on their user ID. - * - * @param userId - The unique identifier of the user whose points are being retrieved. - * @returns A promise that resolves to an object containing the user's total points and their user ID. - */ - async getPointsByRoomSessionUser(@Param('userId') userId: number): Promise<RoomSessionUserPointsResponseDto> { - const points = await this.roomSessionUser.getPointsByRoomSessionUser(userId); - return { ...points, userId }; - } + * + * @param userId - The unique identifier of the user whose points are being retrieved. + * @returns A promise that resolves to an object containing the user's total points and their user ID. + */ + @UseGuards(AuthGuard) + @Get('/user/:userId') + async getPointsByRoomSessionUser(@Param('userId') userId: number): Promise<RoomSessionUserPointsResponseDto> { + const points = await this.roomSessionUser.getPointsByRoomSessionUser(userId); + return { ...points, userId }; + } + } \ No newline at end of file diff --git a/src/room/roomSessionUser.dto.ts b/src/room/roomSessionUser.dto.ts index 3e5e566..9676639 100644 --- a/src/room/roomSessionUser.dto.ts +++ b/src/room/roomSessionUser.dto.ts @@ -1,14 +1,14 @@ export class RoomSessionUserPointsResponseDto { - // points: number; - // userId: number; - // sessionId?: number; - // audioPoints?: number; - // videoPoints?: number; - // browserPoints?: number; - // whiteboardPoints?: number; - // notePoints?: number; allPoints: { audioPoints: number, videoPoints: number, browserPoints: number, whiteboardPoints: number, notePoints: number }; totalPoints: number; sessionId?: number; userId: number; -} \ No newline at end of file +} + +export class RoomSessionUserResponseDto { + id: number; + userId: number; + name: string; + points: RoomSessionUserPointsResponseDto; +} + diff --git a/src/room/roomSessionUser.service.ts b/src/room/roomSessionUser.service.ts index 22d1b39..c870dfa 100644 --- a/src/room/roomSessionUser.service.ts +++ b/src/room/roomSessionUser.service.ts @@ -121,14 +121,14 @@ export class RoomSessionUserService { const points = await this.getPointsByRoomSessionUser(roomSessionUser.id); const sessionPoints = await this.roomSessionService.getAllPointsBySession(roomSessionUser.roomSession.id); let roleTypes: RoleType[] = []; - if (this.shouldAssignModerator(points, sessionPoints)) { - roleTypes.push(RoleType.MODERATOR); + if (this.shouldAssignCoordinator(points, sessionPoints)) { + roleTypes.push(RoleType.COORDINATOR); } - if (this.shouldAssignNoteTaker(points, sessionPoints)) { - roleTypes.push(RoleType.NOTETAKER); + if (this.shouldAssignDocumenter(points, sessionPoints)) { + roleTypes.push(RoleType.DOCUMENTER); } - if (this.shouldAssignGhost(points)) { - roleTypes.push(RoleType.GHOST); + if (this.shouldAssignLurker(points)) { + roleTypes.push(RoleType.LURKER); } for (let role of roleTypes) { await this.roleService.createRole(role, roomSessionUser); @@ -137,18 +137,18 @@ export class RoomSessionUserService { } /** - * Determines whether a user should be assigned as a moderator based on their audio points + * Determines whether a user should be assigned as a Coordinator 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. + * @returns A promise that resolves to a boolean indicating whether the user should be assigned as a Coordinator. */ - private async shouldAssignModerator(points: RoomSessionUserPointsResponseDto, sessionPoints: RoomSessionPointsRequestDto): Promise<boolean> { - let shouldAssignModerator = false; + private async shouldAssignCoordinator(points: RoomSessionUserPointsResponseDto, sessionPoints: RoomSessionPointsRequestDto): Promise<boolean> { + let shouldAssignCoordinator = false; if (points.allPoints.audioPoints/sessionPoints.allPoints.audioPoints > 0.5) { - shouldAssignModerator = true; - return shouldAssignModerator; + shouldAssignCoordinator = true; + return shouldAssignCoordinator; } } @@ -160,12 +160,12 @@ export class RoomSessionUserService { * @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; + private async shouldAssignDocumenter(points: RoomSessionUserPointsResponseDto, sessionPoints: RoomSessionPointsRequestDto): Promise<boolean> { + let shouldAssignDocumenter = false; const userCount = await this.userRepository.count({ roomSession: points.sessionId }); if (points.allPoints.notePoints/sessionPoints.allPoints.notePoints > 1/userCount) { - shouldAssignNoteTaker = true; - return shouldAssignNoteTaker; + shouldAssignDocumenter = true; + return shouldAssignDocumenter; //ToDo: ab wann wird der NoteTaker zugewiesen? mind. 50% der NotePoints im Vergleich zu allen NotePoints? oder wer am meisten NotePoints hat? etc. } } @@ -176,7 +176,7 @@ export class RoomSessionUserService { * @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> { + public async shouldAssignLurker(points: RoomSessionUserPointsResponseDto): Promise<boolean> { return points.allPoints.browserPoints > 10 && points.allPoints.whiteboardPoints > 10; } } -- GitLab