Skip to content

Commit

Permalink
ADD: get room members (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
automerge-pingpong[bot] committed Oct 17, 2023
2 parents cec20d5 + 51a5850 commit dc529a1
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 9 deletions.
26 changes: 17 additions & 9 deletions backend/code/src/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
HttpStatus,
Get,
Query,
Param,
Post,
UseGuards,
} from '@nestjs/common';
Expand All @@ -17,6 +18,7 @@ import { LeaveRoomDto } from './dto/leave-room.dto';
import { DeleteRoomDto } from './dto/delete-room.dto';
import { UpdateRoomDto } from './dto/update-room.dto';
import { ChangeOwnerDto } from './dto/change-owner.dto';
import { QueryOffsetDto } from '../friends/dto/query-ofsset-dto';
import { RoomSearchDto } from './dto/room-search.dto';
import { ApiCookieAuth, ApiResponse, ApiTags } from '@nestjs/swagger';
import { RoomDataDto } from './dto/room-data.dto';
Expand Down Expand Up @@ -138,13 +140,19 @@ export class RoomsController {
return await this.roomsService.getRooms(query);
}

// @Get('members')
// @HttpCode(HttpStatus.OK)
// @UseGuards(AtGuard)
// async getRoomMembers(
// @Query() query: RoomSearchDto,
// @GetCurrentUser('userId') userId: string
// ){
// return await this.roomsService.getRoomMembers(query, userId);
// }
@Get(':id/members')
@HttpCode(HttpStatus.OK)
@UseGuards(AtGuard)
async getRoomMembers(
@Param('id') roomId: string,
@GetCurrentUser('userId') userId: string,
@Query() { offset, limit }: QueryOffsetDto,
) {
return await this.roomsService.getRoomMembers(
roomId,
userId,
offset,
limit,
);
}
}
32 changes: 32 additions & 0 deletions backend/code/src/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,36 @@ export class RoomsService {
return { id: room.id, name: room.name, type: room.type };
});
}

async getRoomMembers(
roomId: string,
userId: string,
offset: number,
limit: number,
) {
const user = await this.prisma.roomMember.findUnique({
where: { unique_user_room: { userId: userId, roomId: roomId } },
});

if (!user)
throw new UnauthorizedException('You are not a member of this room');

return await this.prisma.roomMember.findMany({
skip: offset,
take: limit,
where: {
roomId: roomId,
is_banned: false,
},
select: {
user: {
select: {
userId: true,
firstName: true,
lastName: true,
},
},
},
});
}
}
1 change: 1 addition & 0 deletions backend/code/src/users/users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ export class UsersService {

async getUsers(name: string) {
const users = await this.prisma.user.findMany({
take: 5,
where: {
OR: [
{
Expand Down

0 comments on commit dc529a1

Please sign in to comment.