wip get all public rooms but no users

This commit is contained in:
simplonco
2023-01-08 17:49:36 +01:00
parent b132c154e4
commit f4dc5cde53
7 changed files with 492 additions and 144 deletions

View File

@@ -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 });
}

View File

@@ -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");