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
}

View File

@@ -1,2 +1,2 @@
WEBSITE_HOST=transcendance
WEBSITE_HOST=localhost
WEBSITE_PORT=8080

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,11 @@
<script>
export let content = "warning";
export let bg_color = "rgb(201, 87, 34)";
export let color = "rgb(240, 240, 240)";
</script>
<p style="background-color: {bg_color}; color: {color};">
{content}
</p>

View File

@@ -1,13 +1,16 @@
<script>
<script lang="ts">
import Button from './Chat_button.svelte';
import Warning from './Chat_warning.svelte';
export let layout = "";
export let back = "";
let room_name = "";
let room_type = "";
let room_password = "";
let room_name: string;
let room_type: string;
let room_password: string;
let response_data: string;
let response_status: number = 200;
let response_message: string;
async function handleSubmit(evt)
{
@@ -29,7 +32,10 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
});
console.log(await response.json());
response_data = await response.json();
console.log(response_data);
response_status = response_data.statusCode;
response_message = response_data.message;
}
</script>
@@ -54,6 +60,9 @@
<!-- panel_create -->
<div class="panel panel_create __border_top">
<form on:submit|preventDefault={handleSubmit}>
{#if response_status !== 200}
<Warning content={response_message}/>
{/if}
<!-- name: -->
<label for="chat_name"><p>new room name :</p></label>
<input id="chat_name" bind:value={room_name} name="room_name" required>