Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: get room members #51

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading