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

105
README.md
View File

@@ -1,6 +1,3 @@
- CONFLICT srcs/requirements/svelte/api_front/public/build/bundle.js
- CONFLICT srcs/requirements/svelte/api_front/public/build/bundle.js.map
### Pour lancer le docker : ### Pour lancer le docker :
@@ -134,8 +131,104 @@
--- ---
## hugo ## http status :
- in Chat.svelte, import of socket is not always defined becaus async, tried to solve that in onMount but no luck
```
- '100': 'CONTINUE',
- '101': 'SWITCHING_PROTOCOLS',
- '102': 'PROCESSING',
- '103': 'EARLYHINTS',
- '200': 'OK',
- '201': 'CREATED',
- '202': 'ACCEPTED',
- '203': 'NON_AUTHORITATIVE_INFORMATION',
- '204': 'NO_CONTENT',
- '205': 'RESET_CONTENT',
- '206': 'PARTIAL_CONTENT',
- '300': 'AMBIGUOUS',
- '301': 'MOVED_PERMANENTLY',
- '302': 'FOUND',
- '303': 'SEE_OTHER',
- '304': 'NOT_MODIFIED',
- '307': 'TEMPORARY_REDIRECT',
- '308': 'PERMANENT_REDIRECT',
- '400': 'BAD_REQUEST',
- '401': 'UNAUTHORIZED',
- '402': 'PAYMENT_REQUIRED',
- '403': 'FORBIDDEN',
- '404': 'NOT_FOUND',
- '405': 'METHOD_NOT_ALLOWED',
- '406': 'NOT_ACCEPTABLE',
- '407': 'PROXY_AUTHENTICATION_REQUIRED',
- '408': 'REQUEST_TIMEOUT',
- '409': 'CONFLICT',
- '410': 'GONE',
- '411': 'LENGTH_REQUIRED',
- '412': 'PRECONDITION_FAILED',
- '413': 'PAYLOAD_TOO_LARGE',
- '414': 'URI_TOO_LONG',
- '415': 'UNSUPPORTED_MEDIA_TYPE',
- '416': 'REQUESTED_RANGE_NOT_SATISFIABLE',
- '417': 'EXPECTATION_FAILED',
- '418': 'I_AM_A_TEAPOT',
- '421': 'MISDIRECTED',
- '422': 'UNPROCESSABLE_ENTITY',
- '424': 'FAILED_DEPENDENCY',
- '428': 'PRECONDITION_REQUIRED',
- '429': 'TOO_MANY_REQUESTS',
- '500': 'INTERNAL_SERVER_ERROR',
- '501': 'NOT_IMPLEMENTED',
- '502': 'BAD_GATEWAY',
- '503': 'SERVICE_UNAVAILABLE',
- '504': 'GATEWAY_TIMEOUT',
- '505': 'HTTP_VERSION_NOT_SUPPORTED',
- CONTINUE: 100,
- SWITCHING_PROTOCOLS: 101,
- PROCESSING: 102,
- EARLYHINTS: 103,
- OK: 200,
- CREATED: 201,
- ACCEPTED: 202,
- NON_AUTHORITATIVE_INFORMATION: 203,
- NO_CONTENT: 204,
- RESET_CONTENT: 205,
- PARTIAL_CONTENT: 206,
- AMBIGUOUS: 300,
- MOVED_PERMANENTLY: 301,
- FOUND: 302,
- SEE_OTHER: 303,
- NOT_MODIFIED: 304,
- TEMPORARY_REDIRECT: 307,
- PERMANENT_REDIRECT: 308,
- BAD_REQUEST: 400,
- UNAUTHORIZED: 401,
- PAYMENT_REQUIRED: 402,
- FORBIDDEN: 403,
- NOT_FOUND: 404,
- METHOD_NOT_ALLOWED: 405,
- NOT_ACCEPTABLE: 406,
- PROXY_AUTHENTICATION_REQUIRED: 407,
- REQUEST_TIMEOUT: 408,
- CONFLICT: 409,
- GONE: 410,
- LENGTH_REQUIRED: 411,
- PRECONDITION_FAILED: 412,
- PAYLOAD_TOO_LARGE: 413,
- URI_TOO_LONG: 414,
- UNSUPPORTED_MEDIA_TYPE: 415,
- REQUESTED_RANGE_NOT_SATISFIABLE: 416,
- EXPECTATION_FAILED: 417,
- I_AM_A_TEAPOT: 418,
- MISDIRECTED: 421,
- UNPROCESSABLE_ENTITY: 422,
- FAILED_DEPENDENCY: 424,
- PRECONDITION_REQUIRED: 428,
- TOO_MANY_REQUESTS: 429,
- INTERNAL_SERVER_ERROR: 500,
- NOT_IMPLEMENTED: 501,
- BAD_GATEWAY: 502,
- SERVICE_UNAVAILABLE: 503,
- GATEWAY_TIMEOUT: 504,
- HTTP_VERSION_NOT_SUPPORTED: 505
```

View File

@@ -14,7 +14,8 @@ export class ChatController {
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Get('rooms') @Get('rooms')
async getRooms() { async getRooms()
{
const rooms = await this.chatService.getRooms(); const rooms = await this.chatService.getRooms();
return { rooms }; return { rooms };
} }
@@ -22,28 +23,22 @@ export class ChatController {
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Post('join') @Post('join')
async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req, @Res() res) { async joinRoom(@Body() joinRoomDto: joinRoomDto, @Req() req)
console.log("------ create :"); {
console.log(typeof joinRoomDto); const user: User = req.user;
console.log(joinRoomDto);
console.log(joinRoomDto.room_name);
//const { room_name } = body;
//const user: User = req.user; let room = await this.chatService.addUserToRoom(user, joinRoomDto);
//const { user } = requete;
// let user;
//let room_name;
//await this.chatService.addUserToRoom(user, room_name);
//return { message: 'Successfully joined room.' }; //return { message: 'Successfully joined room.' };
//return res.status(HttpStatus.BAD_REQUEST).json({message : 'You can\'t grant a ticket to another user'}); //return res.status(HttpStatus.BAD_REQUEST).json({message : 'You can\'t grant a ticket to another user'});
return joinRoomDto; return { room };
} }
@UseGuards(AuthenticateGuard) @UseGuards(AuthenticateGuard)
@UseGuards(TwoFactorGuard) @UseGuards(TwoFactorGuard)
@Post('leave') @Post('leave')
async leaveRoom(@Body() body) { async leaveRoom(@Body() body)
{
const { room_id } = body; const { room_id } = body;
// get user // get user
let 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 { User } from 'src/users/entities/user.entity';
import { Chatroom } from './entities/chat.entity'; import { Chatroom } from './entities/chat.entity';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { joinRoomDto } from './dto/joinRoom.dto';
@Injectable() @Injectable()
export class ChatService { export class ChatService {
@@ -24,12 +25,15 @@ export class ChatService {
// return rooms; // return rooms;
} }
async addUserToRoom(user: User, room_name: string) async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
{ {
// get room const room = await this.chatroomRepository.find({ where: { name: joinRoomDto.room_name } });
//if !room {
// create room console.log(HttpStatus);
// add user to room // 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) 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"; import { IsNull } from "typeorm";
export class joinRoomDto { export class joinRoomDto {
@@ -9,6 +9,7 @@ export class joinRoomDto {
@IsNotEmpty() @IsNotEmpty()
room_type : string room_type : string
@IsString() @IsString()
@IsOptional()
room_password : string room_password : string
} }

View File

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