wip create room now receive errors http status

This commit is contained in:
hugogogo
2023-01-06 16:21:36 +01:00
parent d201060dcf
commit 89d25d15f5
9 changed files with 685 additions and 354 deletions

View File

@@ -14,7 +14,8 @@ export class ChatController {
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Get('rooms')
async getRooms() {
async getRooms()
{
const rooms = await this.chatService.getRooms();
return { rooms };
}
@@ -22,28 +23,22 @@ export class ChatController {
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Post('join')
async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req, @Res() res) {
console.log("------ create :");
console.log(typeof joinRoomDto);
console.log(joinRoomDto);
console.log(joinRoomDto.room_name);
//const { room_name } = body;
async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req)
{
const user: User = req.user;
//const user: User = req.user;
//const { user } = requete;
// let user;
//let room_name;
//await this.chatService.addUserToRoom(user, room_name);
let room = await this.chatService.addUserToRoom(user, joinRoomDto);
//return { message: 'Successfully joined room.' };
//return res.status(HttpStatus.BAD_REQUEST).json({message : 'You can\'t grant a ticket to another user'});
return joinRoomDto;
return { room };
}
@UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard)
@Post('leave')
async leaveRoom(@Body() body) {
async leaveRoom(@Body() body)
{
const { room_id } = body;
// get user
let user;

View File

@@ -1,8 +1,9 @@
import { Injectable } from '@nestjs/common';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { User } from 'src/users/entities/user.entity';
import { Chatroom } from './entities/chat.entity';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { joinRoomDto } from './dto/joinRoom.dto';
@Injectable()
export class ChatService {
@@ -24,12 +25,15 @@ export class ChatService {
// return rooms;
}
async addUserToRoom(user: User, room_name: string)
async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
{
// get room
//if !room
// create room
// add user to room
const room = await this.chatroomRepository.find({ where: { name: joinRoomDto.room_name } });
{
console.log(HttpStatus);
// throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
throw new HttpException(`This room already exist`, HttpStatus.OK);
}
return "good room";
}
async removeUserFromRoom(user: User, room_name: string)

View File

@@ -1,4 +1,4 @@
import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString } from "class-validator";
import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
import { IsNull } from "typeorm";
export class joinRoomDto {
@@ -9,6 +9,7 @@ export class joinRoomDto {
@IsNotEmpty()
room_type : string
@IsString()
@IsOptional()
room_password : string
}