Skip to content

Commit

Permalink
ADD: room search (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
automerge-pingpong[bot] committed Oct 16, 2023
2 parents c39d291 + a119dca commit 6c58400
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions backend/code/src/rooms/dto/room-search.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNotEmpty } from 'class-validator';

export class RoomSearchDto {
@ApiProperty()
@IsNotEmpty()
q: string;
}
10 changes: 10 additions & 0 deletions backend/code/src/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
Controller,
HttpCode,
HttpStatus,
Get,
Query,
Post,
UseGuards,
} from '@nestjs/common';
Expand All @@ -18,6 +20,7 @@ import { ChangeOwnerDto } from './dto/change-owner.dto';
import { SetAdminDto } from './dto/set-admin.dto';
import { KickMemberDto } from './dto/kick-member.dto';
import { MuteMemberDto } from './dto/mute-member.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 @@ -130,4 +133,11 @@ export class RoomsController {
) {
return await this.roomsService.muteMember(memberdata, userId);
}

@Get('search')
@HttpCode(HttpStatus.OK)
@UseGuards(AtGuard)
async getRooms(@Query() query: RoomSearchDto) {
return await this.roomsService.getRooms(query);
}
}
18 changes: 18 additions & 0 deletions backend/code/src/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ChangeOwnerDto } from './dto/change-owner.dto';
import { SetAdminDto } from './dto/set-admin.dto';
import { KickMemberDto } from './dto/kick-member.dto';
import { MuteMemberDto } from './dto/mute-member.dto';
import { RoomSearchDto } from './dto/room-search.dto';
import * as bcrypt from 'bcrypt';
import { UpdateRoomDto } from './dto/update-room.dto';
import { RoomDataDto } from './dto/room-data.dto';
Expand Down Expand Up @@ -292,4 +293,21 @@ export class RoomsService {
data: { is_mueted: true, mute_expires: afterFiveMin },
});
}

async getRooms(query: RoomSearchDto) {
const rooms = await this.prisma.room.findMany({
where: {
name: {
contains: query.q,
mode: 'insensitive',
},
type: {
not: 'private',
},
},
});
return rooms.map((room) => {
return { id: room.id, name: room.name, type: room.type };
});
}
}

0 comments on commit 6c58400

Please sign in to comment.