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

add getting room bei sessionId

parent 4ce47325
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@ import { CreateRoom, UpdateRoom } from './room.dto';
import { RoomService } from './room.service';
import { AuthService } from '../auth/auth.service';
import { CategoryService } from '../category/category.service';
import { RoomSessionService } from './roomSession.service';
/**
* Controller responsible for handling room-related endpoints.
......@@ -23,6 +24,7 @@ export class RoomController {
private readonly rooms: RoomService,
private readonly categories: CategoryService,
private readonly auth: AuthService,
private readonly roomSessionService: RoomSessionService,
) {}
/**
......@@ -102,5 +104,11 @@ async getSessions(@Param('roomId') roomId: string): Promise<any[]> {
return sessions;
}
@Get(':roomId/sessions/:sessionId')
async getSession(@Param('roomId') roomId: string, @Param('sessionId') sessionId: string): Promise<any> {
const session = await this.roomSessionService.getRoomSessionById(parseInt(sessionId));
return session;
}
}
......@@ -61,6 +61,29 @@ export class RoomSessionService {
await this.em.persistAndFlush(roomSession);
}
public async getRoomSessionById(id: number) {
try {
const roomSession = await this.repository.findOneOrFail({ id });
const users = await this.em.find(RoomSessionUser, { roomSession: roomSession.id });
return {
id: roomSession.id,
dateOpened: roomSession.dateOpened,
dateClosed: roomSession.dateClosed,
roomId: roomSession.room.id,
users: users.map(user => ({
id: user.id,
userId: user.userId,
name: user.name
}))
};
}
catch (error) {
console.error('Error in getRoomSessionById:', error);
throw error;
}
}
public async getAllPointsBySession(sessionId: number): Promise<RoomSessionPointsRequestDto> {
const roomSessionUsers = await this.roomSessionUserRepository.find({ roomSession: sessionId });
const points = await Promise.all(roomSessionUsers.map(user => this.roomSessionUserService.getPointsByRoomSessionUser(user.id)));
......
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