wip get all public rooms but no users
This commit is contained in:
@@ -14,11 +14,21 @@ export class ChatController {
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('rooms')
|
||||
async getRooms(@Req() req, @Res() res): Promise<object>
|
||||
@Get('myrooms')
|
||||
async getMyRooms(@Req() req, @Res() res): Promise<object>
|
||||
{
|
||||
console.log("- in getRooms controller");
|
||||
const rooms = await this.chatService.getRooms(req.user);
|
||||
console.log("- in getMyRooms controller");
|
||||
const rooms = await this.chatService.getMyRooms(req.user);
|
||||
return res.status(HttpStatus.OK).json({ rooms: rooms });
|
||||
}
|
||||
|
||||
@UseGuards(AuthenticateGuard)
|
||||
@UseGuards(TwoFactorGuard)
|
||||
@Get('allrooms')
|
||||
async getAllRooms(@Req() req, @Res() res): Promise<object>
|
||||
{
|
||||
console.log("- in getAllRooms controller");
|
||||
const rooms = await this.chatService.getAllNotMyRooms(req.user);
|
||||
return res.status(HttpStatus.OK).json({ rooms: rooms });
|
||||
}
|
||||
|
||||
|
||||
@@ -24,13 +24,29 @@ export class ChatService {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
}
|
||||
|
||||
async getRooms(user: User)
|
||||
async getMyRooms(user: User)
|
||||
{
|
||||
console.log("-- in getRooms service");
|
||||
console.log("-- in getMyRooms service");
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where(':user_id IN (chatroom.users)', { user_id: user.fortyTwoId })
|
||||
.getMany();
|
||||
|
||||
return rooms;
|
||||
}
|
||||
|
||||
async getAllNotMyRooms(user: User)
|
||||
{
|
||||
console.log("-- in getAllNotMyRooms service");
|
||||
const user_db = await this.usersService.findOneByFourtyTwoId(user.fortyTwoId);
|
||||
const rooms = await this.chatroomRepository
|
||||
.createQueryBuilder('chatroom')
|
||||
.where('chatroom.type != :type', { type: 'private' })
|
||||
.andWhere(':user_id NOT IN (chatroom.users)', { user_id: user.fortyTwoId })
|
||||
.getMany();
|
||||
//const users = await this.findAllUsers();
|
||||
//let allRooms = [...rooms, ...users];
|
||||
|
||||
return rooms;
|
||||
}
|
||||
|
||||
@@ -58,6 +74,8 @@ export class ChatService {
|
||||
return room;
|
||||
}
|
||||
|
||||
/* temp *****************************************
|
||||
*/
|
||||
async findUserByName(name: string)
|
||||
{
|
||||
console.log("-- in findUserByName service");
|
||||
@@ -69,6 +87,18 @@ export class ChatService {
|
||||
return user;
|
||||
}
|
||||
|
||||
/* temp *****************************************
|
||||
*/
|
||||
async findAllUsers()
|
||||
{
|
||||
console.log("-- in findAllUsers service");
|
||||
const users = await this.userRepository
|
||||
.createQueryBuilder('user')
|
||||
.getMany();
|
||||
|
||||
return users;
|
||||
}
|
||||
|
||||
async setCurrentRoom(user: User, name: string)
|
||||
{
|
||||
console.log("-- in setCurrentRoom service");
|
||||
|
||||
Reference in New Issue
Block a user