wip trying to create first instance of chatroom in db

This commit is contained in:
hugogogo
2023-01-06 16:56:36 +01:00
parent 89d25d15f5
commit 23105600a5
8 changed files with 60 additions and 47 deletions

View File

@@ -5,7 +5,7 @@ import { ChatGateway } from './chat.gateway';
import { UsersModule } from 'src/users/users.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Chatroom } from './entities/chat.entity';
import { Chatroom } from './entities/chatroom.entity';
import { User } from 'src/users/entities/user.entity';
@Module({

View File

@@ -1,6 +1,6 @@
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { User } from 'src/users/entities/user.entity';
import { Chatroom } from './entities/chat.entity';
import { Chatroom } from './entities/chatroom.entity';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { joinRoomDto } from './dto/joinRoom.dto';
@@ -21,18 +21,26 @@ export class ChatService {
async getRooms()
{
// get rooms
// return rooms;
}
async getUserRooms()
{
}
async addUserToRoom(user: User, joinRoomDto: joinRoomDto)
{
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);
}
const room = await this.chatroomRepository.findOneBy({ name : joinRoomDto.room_name })
console.log(room);
if (room)
throw new HttpException(`This room already exist`, HttpStatus.CONFLICT);
const newChatroom = new Chatroom();
newChatroom.name = joinRoomDto.room_name;
newChatroom.type = joinRoomDto.room_type;
newChatroom.owner = user;
const savedChatroom = this.chatroomRepository.save(newChatroom);
console.log(savedChatroom);
return "good room";
}

View File

@@ -1,4 +1,4 @@
import { IsBoolean, IsEmpty, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
import { IsBoolean, IsEmpty, IsIn, IsInt, IsNotEmpty, IsNumber, IsString, IsOptional } from "class-validator";
import { IsNull } from "typeorm";
export class joinRoomDto {
@@ -7,6 +7,7 @@ export class joinRoomDto {
room_name : string
@IsString()
@IsNotEmpty()
@IsIn(['public', 'private', 'direct'])
room_type : string
@IsString()
@IsOptional()

View File

@@ -3,7 +3,7 @@ import { IsEmail, Length } from "class-validator";
import { Column, Entity, JoinColumn, JoinTable, ManyToMany, OneToMany, OneToOne, PrimaryGeneratedColumn, Unique } from "typeorm";
import { Friendship } from "../../friendship/entities/friendship.entity";
import { UserStats } from "./userStat.entities";
import { Chatroom } from "src/chat/entities/chat.entity";
import { Chatroom } from "src/chat/entities/chatroom.entity";
@Entity('user')

View File

@@ -10471,7 +10471,7 @@ var app = (function () {
const { console: console_1$8 } = globals;
const file$h = "src/pieces/chat/Layout_create.svelte";
// (37:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
// (41:1) <Button bind:layout new_layout={back} my_class="back icon" my_title="go back {back}">
function create_default_slot_2$3(ctx) {
let t;
@@ -10491,14 +10491,14 @@ var app = (function () {
block,
id: create_default_slot_2$3.name,
type: "slot",
source: "(37:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
source: "(41:1) <Button bind:layout new_layout={back} my_class=\\\"back icon\\\" my_title=\\\"go back {back}\\\">",
ctx
});
return block;
}
// (42:1) <Button my_class="create deactivate">
// (46:1) <Button my_class="create deactivate">
function create_default_slot_1$3(ctx) {
let t;
@@ -10518,14 +10518,14 @@ var app = (function () {
block,
id: create_default_slot_1$3.name,
type: "slot",
source: "(42:1) <Button my_class=\\\"create deactivate\\\">",
source: "(46:1) <Button my_class=\\\"create deactivate\\\">",
ctx
});
return block;
}
// (47:1) <Button bind:layout new_layout="close" my_class="close icon">
// (51:1) <Button bind:layout new_layout="close" my_class="close icon">
function create_default_slot$5(ctx) {
let t;
@@ -10545,14 +10545,14 @@ var app = (function () {
block,
id: create_default_slot$5.name,
type: "slot",
source: "(47:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
source: "(51:1) <Button bind:layout new_layout=\\\"close\\\" my_class=\\\"close icon\\\">",
ctx
});
return block;
}
// (54:3) {#if response_status !== 200}
// (58:3) {#if response_status !== 200}
function create_if_block_1$5(ctx) {
let warning;
let current;
@@ -10593,14 +10593,14 @@ var app = (function () {
block,
id: create_if_block_1$5.name,
type: "if",
source: "(54:3) {#if response_status !== 200}",
source: "(58:3) {#if response_status !== 200}",
ctx
});
return block;
}
// (76:3) {#if room_type === 'protected'}
// (80:3) {#if room_type === 'protected'}
function create_if_block$b(ctx) {
let div;
let label;
@@ -10619,10 +10619,10 @@ var app = (function () {
t1 = space();
input = element("input");
attr_dev(p, "class", "svelte-1b1eu8h");
add_location(p, file$h, 77, 28, 2450);
add_location(p, file$h, 81, 28, 2563);
attr_dev(label, "for", "chat_pswd");
attr_dev(label, "class", "svelte-1b1eu8h");
add_location(label, file$h, 77, 5, 2427);
add_location(label, file$h, 81, 5, 2540);
attr_dev(input, "id", "chat_pswd");
attr_dev(input, "type", "password");
attr_dev(input, "placeholder", "minimum 8 characters");
@@ -10630,9 +10630,9 @@ var app = (function () {
attr_dev(input, "name", "password");
input.required = true;
attr_dev(input, "class", "svelte-1b1eu8h");
add_location(input, file$h, 78, 5, 2490);
add_location(input, file$h, 82, 5, 2603);
attr_dev(div, "class", "svelte-1b1eu8h");
add_location(div, file$h, 76, 4, 2416);
add_location(div, file$h, 80, 4, 2529);
},
m: function mount(target, anchor) {
insert_dev(target, div, anchor);
@@ -10663,7 +10663,7 @@ var app = (function () {
block,
id: create_if_block$b.name,
type: "if",
source: "(76:3) {#if room_type === 'protected'}",
source: "(80:3) {#if room_type === 'protected'}",
ctx
});
@@ -10798,17 +10798,17 @@ var app = (function () {
t16 = space();
input4 = element("input");
attr_dev(p0, "class", "svelte-1b1eu8h");
add_location(p0, file$h, 57, 26, 1613);
add_location(p0, file$h, 61, 26, 1726);
attr_dev(label0, "for", "chat_name");
attr_dev(label0, "class", "svelte-1b1eu8h");
add_location(label0, file$h, 57, 3, 1590);
add_location(label0, file$h, 61, 3, 1703);
attr_dev(input0, "id", "chat_name");
attr_dev(input0, "name", "room_name");
input0.required = true;
attr_dev(input0, "class", "svelte-1b1eu8h");
add_location(input0, file$h, 58, 3, 1647);
add_location(input0, file$h, 62, 3, 1760);
attr_dev(p1, "class", "svelte-1b1eu8h");
add_location(p1, file$h, 61, 4, 1790);
add_location(p1, file$h, 65, 4, 1903);
attr_dev(input1, "id", "chat_public");
attr_dev(input1, "type", "radio");
attr_dev(input1, "name", "room_type");
@@ -10817,12 +10817,12 @@ var app = (function () {
input1.required = true;
attr_dev(input1, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[12][0].push(input1);
add_location(input1, file$h, 62, 4, 1808);
add_location(input1, file$h, 66, 4, 1921);
attr_dev(label1, "for", "chat_public");
attr_dev(label1, "class", "_radio svelte-1b1eu8h");
add_location(label1, file$h, 60, 3, 1745);
add_location(label1, file$h, 64, 3, 1858);
attr_dev(p2, "class", "svelte-1b1eu8h");
add_location(p2, file$h, 66, 4, 1996);
add_location(p2, file$h, 70, 4, 2109);
attr_dev(input2, "id", "chat_private");
attr_dev(input2, "type", "radio");
attr_dev(input2, "name", "room_type");
@@ -10831,12 +10831,12 @@ var app = (function () {
input2.required = true;
attr_dev(input2, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[12][0].push(input2);
add_location(input2, file$h, 67, 4, 2015);
add_location(input2, file$h, 71, 4, 2128);
attr_dev(label2, "for", "chat_private");
attr_dev(label2, "class", "_radio svelte-1b1eu8h");
add_location(label2, file$h, 65, 3, 1950);
add_location(label2, file$h, 69, 3, 2063);
attr_dev(p3, "class", "svelte-1b1eu8h");
add_location(p3, file$h, 71, 4, 2209);
add_location(p3, file$h, 75, 4, 2322);
attr_dev(input3, "id", "chat_protected");
attr_dev(input3, "type", "radio");
attr_dev(input3, "name", "room_type");
@@ -10845,20 +10845,20 @@ var app = (function () {
input3.required = true;
attr_dev(input3, "class", "svelte-1b1eu8h");
/*$$binding_groups*/ ctx[12][0].push(input3);
add_location(input3, file$h, 72, 4, 2230);
add_location(input3, file$h, 76, 4, 2343);
attr_dev(label3, "for", "chat_protected");
attr_dev(label3, "class", "_radio svelte-1b1eu8h");
add_location(label3, file$h, 70, 3, 2161);
add_location(label3, file$h, 74, 3, 2274);
attr_dev(input4, "type", "submit");
input4.value = "⮡";
attr_dev(input4, "class", "svelte-1b1eu8h");
add_location(input4, file$h, 81, 3, 2654);
add_location(input4, file$h, 85, 3, 2767);
attr_dev(form, "class", "svelte-1b1eu8h");
add_location(form, file$h, 52, 2, 1438);
add_location(form, file$h, 56, 2, 1551);
attr_dev(div0, "class", "panel panel_create __border_top svelte-1b1eu8h");
add_location(div0, file$h, 51, 1, 1390);
add_location(div0, file$h, 55, 1, 1503);
attr_dev(div1, "class", "grid_box svelte-1b1eu8h");
add_location(div1, file$h, 33, 0, 1045);
add_location(div1, file$h, 37, 0, 1158);
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
@@ -11073,8 +11073,8 @@ var app = (function () {
response_data = await response.json();
console.log(response_data);
$$invalidate(5, response_status = response_data.statusCode);
$$invalidate(6, response_message = response_data.message);
if (response_data.statusCode) $$invalidate(5, response_status = response_data.statusCode); else $$invalidate(5, response_status = 200);
if (response_data.message) $$invalidate(6, response_message = response_data.message);
}
const writable_props = ['layout', 'back'];

File diff suppressed because one or more lines are too long

View File

@@ -34,8 +34,12 @@
});
response_data = await response.json();
console.log(response_data);
response_status = response_data.statusCode;
response_message = response_data.message;
if (response_data.statusCode)
response_status = response_data.statusCode;
else
response_status = 200;
if (response_data.message)
response_message = response_data.message;
}
</script>