From 8be84e84423477553e9c49b629a4de27f1b2c255 Mon Sep 17 00:00:00 2001 From: hugogogo Date: Fri, 6 Jan 2023 17:13:59 +0100 Subject: [PATCH] rooms creation ok in db --- .../nestjs/api_back/src/chat/chat.service.ts | 2 +- .../nestjs/api_back/src/chat/dto/joinRoom.dto.ts | 8 +++++--- .../api_back/src/chat/entities/chatroom.entity.ts | 12 +++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts index 720375f7..ae0c1f08 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/chat.service.ts @@ -38,7 +38,7 @@ export class ChatService { newChatroom.name = joinRoomDto.room_name; newChatroom.type = joinRoomDto.room_type; newChatroom.owner = user; - const savedChatroom = this.chatroomRepository.save(newChatroom); + const savedChatroom = await this.chatroomRepository.save(newChatroom); console.log(savedChatroom); return "good room"; diff --git a/srcs/requirements/nestjs/api_back/src/chat/dto/joinRoom.dto.ts b/srcs/requirements/nestjs/api_back/src/chat/dto/joinRoom.dto.ts index 1224d395..d395517f 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/dto/joinRoom.dto.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/dto/joinRoom.dto.ts @@ -1,14 +1,16 @@ -import { IsBoolean, IsEmpty, IsIn, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator"; +import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator"; import { IsNull } from "typeorm"; export class joinRoomDto { + @IsString() @IsNotEmpty() room_name : string + @IsString() @IsNotEmpty() - @IsIn(['public', 'private', 'direct']) - room_type : string + room_type : 'public' | 'private' | 'direct'; + @IsString() @IsOptional() room_password : string diff --git a/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts b/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts index fa482347..bcdf0a74 100644 --- a/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts +++ b/srcs/requirements/nestjs/api_back/src/chat/entities/chatroom.entity.ts @@ -9,18 +9,16 @@ import { User } from 'src/users/entities/user.entity'; @Entity('chatroom') export class Chatroom { @PrimaryGeneratedColumn() - id: number; + id: number; @Column() - name: string; + name: string; @Column() - type: 'public' | 'private' | 'direct'; - - @Column({ nullable: true }) - protection: boolean; + type: 'public' | 'private' | 'direct'; @ManyToOne(type => User, user => user.ownedRoom) - owner: User; + owner: User; + }