Chatrooms created
This commit is contained in:
parent
5e2996c0fd
commit
042e3b9862
12
server/controllers/chat_room.controller.ts
Normal file
12
server/controllers/chat_room.controller.ts
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
43
server/database/migrations/1648605030863-AddChatRoom.ts
Normal file
43
server/database/migrations/1648605030863-AddChatRoom.ts
Normal 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');
|
||||||
|
}
|
||||||
|
}
|
19
server/entities/chat_room.entity.ts
Normal file
19
server/entities/chat_room.entity.ts
Normal 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;
|
||||||
|
}
|
13
server/modules/chat_room.module.ts
Normal file
13
server/modules/chat_room.module.ts
Normal 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 {}
|
24
server/providers/services/chat_room.service.ts
Normal file
24
server/providers/services/chat_room.service.ts
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user