Skip to content
Snippets Groups Projects
Commit 75dd763b authored by L4072's avatar L4072
Browse files

Database edited. TypeORM

parent 9a4447d8
No related branches found
No related tags found
4 merge requests!59Development to master,!14Type orm,!13Type orm,!11Type orm
...@@ -8,12 +8,13 @@ import { UserModule } from './user/user.module'; ...@@ -8,12 +8,13 @@ import { UserModule } from './user/user.module';
import { HttpErrorFilter } from './shared/http-error.filter'; import { HttpErrorFilter } from './shared/http-error.filter';
import { LoggingInterceptor } from './shared/logging.interceptor'; import { LoggingInterceptor } from './shared/logging.interceptor';
import { MapMarkerModule } from './mapmarkers/mapmarkers.module'; import { MapMarkerModule } from './mapmarkers/mapmarkers.module';
import { GameController } from './game/game.controller';
@Module({ @Module({
imports: [TypeOrmModule.forRoot(), UserModule, MapMarkerModule], imports: [TypeOrmModule.forRoot(), UserModule, MapMarkerModule],
controllers: [AppController], controllers: [AppController, GameController],
providers: [ providers: [
AppService, { AppService, {
provide: APP_FILTER, provide: APP_FILTER,
......
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, ManyToMany, OneToMany, ManyToOne, JoinTable } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, ManyToMany, OneToMany, ManyToOne, JoinTable, Timestamp } from 'typeorm';
import {Game_PersonEntity, ObjectivePointEntity, GameEntity} from './game.entity' import {Game_PersonEntity, ObjectivePointEntity, GameEntity} from './game.entity'
import { FactionEntity } from './faction.entity' import { FactionEntity } from './faction.entity'
//import { MapEntity, MapDrawingEntity } from '../map/map.entity' //import { MapEntity, MapDrawingEntity } from '../map/map.entity'
...@@ -8,6 +8,7 @@ export class CoordinateEntity { ...@@ -8,6 +8,7 @@ export class CoordinateEntity {
@PrimaryGeneratedColumn('uuid') coordinateId: string; @PrimaryGeneratedColumn('uuid') coordinateId: string;
@Column({type: 'geometry'}) longitude: string; @Column({type: 'geometry'}) longitude: string;
@Column({type: 'geometry'}) latitude: string; @Column({type: 'geometry'}) latitude: string;
@Column() coordinateTimestamp: Timestamp;
@ManyToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawings_coordinates) @ManyToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawings_coordinates)
mapDrawings: MapDrawingEntity[]; mapDrawings: MapDrawingEntity[];
......
import { Test, TestingModule } from '@nestjs/testing';
import { GameController } from './game.controller';
describe('Game Controller', () => {
let controller: GameController;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
controllers: [GameController],
}).compile();
controller = module.get<GameController>(GameController);
});
it('should be defined', () => {
expect(controller).toBeDefined();
});
});
import { Controller, Post, Body } from '@nestjs/common'; import { Controller } from '@nestjs/common';
import {CreateGameDTO} from './game.dto'
@Controller('game') @Controller('game')
export class GameController{ export class GameController {
@Post()
create(@Body() data: CreateGameDTO) { }
return this//.gameService.register(data);
}
}
\ No newline at end of file
...@@ -22,9 +22,6 @@ export class CreateGameDTO { ...@@ -22,9 +22,6 @@ export class CreateGameDTO {
@IsArray() @IsNotEmpty() @IsArray() @IsNotEmpty()
factions?: FactionEntity[]; factions?: FactionEntity[];
@IsArray() @IsNotEmpty()
powerUps?: PowerUpDTO[];
@IsArray() @IsNotEmpty() @IsArray() @IsNotEmpty()
objectivePoint?: ObjectivePointDTO[]; objectivePoint?: ObjectivePointDTO[];
...@@ -44,7 +41,7 @@ export class FactionDTO { ...@@ -44,7 +41,7 @@ export class FactionDTO {
} }
export class PowerUpDTO { /*export class PowerUpDTO {
@IsString() @IsNotEmpty() @IsString() @IsNotEmpty()
powerUpName: string; powerUpName: string;
...@@ -56,7 +53,7 @@ export class PowerUpDTO { ...@@ -56,7 +53,7 @@ export class PowerUpDTO {
@IsNotEmpty() @IsNotEmpty()
cooldown: string; cooldown: string;
} }*/
export class ObjectivePointDTO { export class ObjectivePointDTO {
@IsString() @IsNotEmpty() @IsString() @IsNotEmpty()
......
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, ManyToMany, Timestamp, JoinTable } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, ManyToMany, Timestamp, JoinTable } from 'typeorm';
import * as bcrypt from 'bcryptjs';
import {PersonEntity, PersonRoleEntity} from '../user/user.entity' import {PersonEntity, PersonRoleEntity} from '../user/user.entity'
import {FactionEntity} from './faction.entity' import {FactionEntity} from './faction.entity'
import {CoordinateEntity} from './coordinate.entity' import {CoordinateEntity, MapEntity} from './coordinate.entity'
import { MapEntity } from './coordinate.entity'
@Entity('Game') @Entity('Game')
export class GameEntity { export class GameEntity {
...@@ -23,8 +23,12 @@ export class GameEntity { ...@@ -23,8 +23,12 @@ export class GameEntity {
objective_points: ObjectivePointEntity[]; objective_points: ObjectivePointEntity[];
gameObject() { gameObject() {
const {gameId, gameName, gameDescription, startDate, endDate, GM_Password} = this; const {gameId, gameName, gameDescription, startDate, endDate, factions, objective_points, map, GM_Password} = this;
return this; return {gameId, gameName, gameDescription, startDate, endDate, factions, objective_points, map, GM_Password};
}
async comparePassword(attempt: string) {
return await bcrypt.compareSync(attempt, this.GM_Password);
} }
} }
......
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { GameController } from './game.controller';
import { GameService } from './game.service';
import { GameEntity } from './game.entity';
@Module({
imports: [TypeOrmModule.forFeature([GameEntity])],
controllers: [GameController],
providers: [GameService]
})
export class GameModule {}
\ No newline at end of file
...@@ -6,18 +6,18 @@ import { GameEntity } from './game.entity'; ...@@ -6,18 +6,18 @@ import { GameEntity } from './game.entity';
import { CreateGameDTO } from './game.dto'; import { CreateGameDTO } from './game.dto';
@Injectable() @Injectable()
export class UserService { export class GameService {
constructor(@InjectRepository(GameEntity) private userRepository: Repository<GameEntity>){} constructor(@InjectRepository(GameEntity) private userRepository: Repository<GameEntity>){}
async register(data: CreateGameDTO) { async register(data: CreateGameDTO) {
const { gameName } = data; const { gameName } = data;
let user = await this.userRepository.findOne({where: {name}}); let game = await this.userRepository.findOne({where: {gameName}});
if (user) { if (game) {
throw new HttpException('User already exists', HttpStatus.BAD_REQUEST); throw new HttpException('Game with this name already exists', HttpStatus.BAD_REQUEST);
} }
user = await this.userRepository.create(data); game = await this.userRepository.create(data);
await this.userRepository.save(user); await this.userRepository.save(game);
return user.gameObject(); return game.gameObject();
} }
/*async login(data: UserDTO) { /*async login(data: UserDTO) {
......
...@@ -3,7 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm'; ...@@ -3,7 +3,7 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { UserController } from './user.controller'; import { UserController } from './user.controller';
import { UserService } from './user.service'; import { UserService } from './user.service';
import { PersonEntity} from './user.entity'; import { PersonEntity } from './user.entity';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([PersonEntity])], imports: [TypeOrmModule.forFeature([PersonEntity])],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment