Chatrooms created

This commit is contained in:
Logan Hunt 2022-03-29 20:17:08 -06:00
parent 5e2996c0fd
commit 042e3b9862
Signed by untrusted user who does not match committer: simponic
GPG Key ID: 52B3774857EB24B1
5 changed files with 111 additions and 0 deletions

View File

@ -0,0 +1,12 @@
import { Controller, Get } from '@nestjs/common';
import { ChatRoomService } from 'server/providers/services/chat_room.service';
@Controller()
export class ChatRoomController {
constructor(private chatRoomService: ChatRoomService) {}
@Get('/chat_rooms')
async get() {
return await this.chatRoomService.all();
}
}

View File

@ -0,0 +1,43 @@
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
export class AddChatRoom1648605030863 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.createTable(
new Table({
name: 'chatroom',
columns: [
{
name: 'id',
type: 'int',
isPrimary: true,
isGenerated: true,
},
{
name: 'name',
type: 'text',
isNullable: false,
},
{
name: 'latitude',
type: 'float',
isNullable: false,
},
{
name: 'longitude',
type: 'float',
isNullable: false,
},
{
name: 'radius',
type: 'float',
isNullable: false,
},
],
}),
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.dropTable('chatroom');
}
}

View File

@ -0,0 +1,19 @@
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
@Entity()
export class ChatRoom {
@PrimaryGeneratedColumn()
id: number;
@Column()
name: string;
@Column()
latitude: number;
@Column()
longitude: number;
@Column()
radius: number;
}

View File

@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ChatRoomController } from 'server/controllers/chat_room.controller';
import { ChatRoom } from 'server/entities/chat_room.entity';
import { ChatRoomService } from 'server/providers/services/chat_room.service';
@Module({
imports: [TypeOrmModule.forFeature([ChatRoom])],
controllers: [ChatRoomController],
providers: [ChatRoomService],
exports: [TypeOrmModule],
})
export class UsersModule {}

View File

@ -0,0 +1,24 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ChatRoom } from 'server/entities/chat_room.entity';
@Injectable()
export class ChatRoomService {
constructor(
@InjectRepository(ChatRoom)
private chatRoomRepository: Repository<ChatRoom>,
) {}
create(chatRoom: ChatRoom) {
return this.chatRoomRepository.save(chatRoom);
}
all() {
return this.chatRoomRepository.find();
}
findById(id: number) {
return this.chatRoomRepository.findOne(id);
}
}