From 8d6e7d465bc36a80d9652608df4a73f7479fc702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Syd=C3=A4nmaa?= <L4072@student.jamk.fi> Date: Tue, 18 Jun 2019 13:38:37 +0300 Subject: [PATCH] Merge conflicts fixed --- src/game/game.controller.ts | 6 +- src/game/game.dto.ts | 4 +- src/game/game.entity.ts | 166 ++++++++++++++++++++++++++++++++---- src/game/game.service.ts | 10 +-- 4 files changed, 161 insertions(+), 25 deletions(-) diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index eafada8..bba4916 100644 --- a/src/game/game.controller.ts +++ b/src/game/game.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Post, UseGuards, Body, Get, Param, UsePipes, Put } from '@nestjs/common'; +import { Controller, Post, UseGuards, Body, Get, Param, UsePipes, Put, Delete } from '@nestjs/common'; import { GameService } from './game.service'; import { AuthGuard } from '../shared/auth.guard'; @@ -13,14 +13,14 @@ export class GameController { @Post('new') @UseGuards(new AuthGuard()) @UsePipes(new ValidationPipe()) - async newGame(@User('id') person, @Body() body: CreateGameDTO ) { + async newGame(@User('id') person, @Body() body: GameDTO ) { return this.gameservice.createNewGame(person, body); } @Put(':id') @UseGuards(new AuthGuard()) @UsePipes(new ValidationPipe()) - async editGame(@Param('id') id: string, @Body() body: CreateGameDTO) { + async editGame(@Param('id') id: string, @Body() body: GameDTO) { return this.gameservice.editGame(id, body); } diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts index da61196..45904f6 100644 --- a/src/game/game.dto.ts +++ b/src/game/game.dto.ts @@ -1,9 +1,9 @@ import { IsNotEmpty, IsString, IsDate, Length, IsInt, Min, Max, IsArray, IsJSON } from 'class-validator'; import { Timestamp } from 'typeorm'; -export class CreateGameDTO { +export class GameDTO { @IsString() @IsNotEmpty() @Length(3, 30) - gameName: string; + name: string; @IsString() gameDescription?: string; diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index 9600424..d4ffa1a 100644 --- a/src/game/game.entity.ts +++ b/src/game/game.entity.ts @@ -5,8 +5,9 @@ import { ManyToOne, OneToMany, Timestamp, + PrimaryColumn, } from 'typeorm'; -import { PersonEntity } from 'src/user/user.entity'; +import { PersonEntity, PersonRoleEntity } from 'src/user/user.entity'; // table that stores all created games @Entity('Game') @@ -18,12 +19,15 @@ export class GameEntity { @Column('json') map: JSON; @Column('timestamp') startdate: Timestamp; @Column('timestamp') enddate: Timestamp; - @Column("text", {array: true}) passwords: string[]; + + @ManyToOne(type => MapEntity, map => map.games) + gamemap: MapEntity; @OneToMany(type => FactionEntity, faction => faction.game) factions: FactionEntity[]; @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game) game_persons: Game_PersonEntity[]; - + @OneToMany(type => ObjectivePointEntity, objective_points => objective_points.game) + objective_points: ObjectivePointEntity[]; gameObject() { const { id, name } = this; @@ -31,18 +35,6 @@ export class GameEntity { } } -// table that stores all factions created for games -@Entity('Faction') -export class FactionEntity { - @PrimaryGeneratedColumn('uuid') id: string; - @Column('text') name: string; - @ManyToOne(type => GameEntity, game => game.factions) - game: GameEntity; - @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) - game_persons: Game_PersonEntity[]; - -} - // table that stores players associated with particular game @Entity('Game_Person') export class Game_PersonEntity { @@ -81,4 +73,148 @@ export class ObjectivePoint_HistoryEntity { @ManyToOne(type => ObjectivePointEntity, objective_point => objective_point.op_history) objective_point: ObjectivePointEntity; +} + +// table that stores all factions created for games +/*@Entity('Faction') +export class FactionEntity { + @PrimaryGeneratedColumn('uuid') id: string; + @Column('text') name: string; + @ManyToOne(type => GameEntity, game => game.factions) + game: GameEntity; + @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) + game_persons: Game_PersonEntity[]; + +}*/ + +@Entity('Faction') +export class FactionEntity { + @PrimaryGeneratedColumn('uuid') factionId: string; + @Column({type: 'text', unique: true}) factionName: string; + @Column({type: 'text'}) factionPassword: string; + @Column({type: 'float'}) multiplier: number; + + @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction) + mapDrawings: MapDrawingEntity[]; + @OneToMany(type => ScoreEntity, scores => scores.faction) + scores: ScoreEntity[]; + @OneToMany(type => PowerUpEntity, powerUps => powerUps.factions) + powerUps: Faction_PowerUpEntity[]; + @OneToMany(type => TaskEntity, tasks => tasks.faction) + tasks: TaskEntity[]; + @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) + game_persons: Game_PersonEntity[]; + @ManyToOne(type => GameEntity, game => game.factions) + game: GameEntity; +} + +@Entity('PowerUp') +export class PowerUpEntity { + @PrimaryGeneratedColumn('uuid') powerUpId: string; + @Column({type: 'text'}) powerUpName: string; + @Column({type: 'text'}) powerUpDescription: string; + @Column({type: 'int'}) amount: number; + @Column({type: 'time'}) cooldown: string; + + @OneToMany(type => FactionEntity, factions => factions.powerUps) + factions: Faction_PowerUpEntity[]; + +} + +@Entity('Faction_PowerUp') +export class Faction_PowerUpEntity{ + @PrimaryGeneratedColumn('uuid') faction_powerUpId: string; + + @ManyToOne(type => FactionEntity, faction => faction.powerUps) + faction: FactionEntity; + @ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions) + powerUp: PowerUpEntity; + @OneToMany(type => FP_HistoryEntity, histories => histories.faction_PowerUp) + histories: FP_HistoryEntity[]; +} + +@Entity('FP_History') +export class FP_HistoryEntity{ + @PrimaryGeneratedColumn('uuid') historyId: string; + @Column({type: 'timestamp'}) historyTimeStamp: Timestamp; + + @ManyToOne(type => Faction_PowerUpEntity, faction_PowerUp => faction_PowerUp.histories) + faction_PowerUp: Faction_PowerUpEntity; +} + +@Entity('Score') +export class ScoreEntity { + @PrimaryGeneratedColumn('uuid') scoreId: string; + @Column({type: 'float'}) score: number; + @Column({type: 'timestamp'}) scoreTimeStamp: Timestamp; + + @ManyToOne(type => FactionEntity, factionName => factionName.scores) + faction: FactionEntity; +} + +@Entity('Task') +export class TaskEntity { + @PrimaryGeneratedColumn('uuid') taskId: string; + @Column({type: 'text'}) taskName: string; + @Column({type: 'text'}) taskDescription: string; + @Column({type: 'text'}) taskWinner: string; + @Column({type: 'bool'}) taskIsActive: boolean; + + @ManyToOne(type => FactionEntity, faction => faction.tasks) + faction: FactionEntity; + @ManyToOne(type => PersonEntity, person => person.tasks) + person: PersonEntity; +} + +@Entity('Coordinate') +export class CoordinateEntity { + @PrimaryColumn({type: 'json', nullable: true}) features: JSON; + + @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawings_coordinates) + mapDrawings: MapDrawingEntity[]; + @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game_person_coordinates) + game_persons: Game_PersonEntity[]; + @OneToMany(type => ObjectivePointEntity, objective_points => objective_points.coordinate) + objective_points: ObjectivePointEntity[]; + @OneToMany(type => MapEntity, maps => maps.coordinate) + maps: ObjectivePointEntity[]; +} + + +@Entity('Map') +export class MapEntity { + @PrimaryGeneratedColumn('uuid') mapId: string; + + @ManyToOne(type => CoordinateEntity, coordinate => coordinate.maps) + coordinate: CoordinateEntity; + @OneToMany(type => GameEntity, games => games.gamemap) + games: GameEntity[]; + @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.map) + mapDrawings: MapDrawingEntity[]; +} + +@Entity('MapDrawing') +export class MapDrawingEntity { + @PrimaryGeneratedColumn('uuid') mapDrawingId: string; + @Column({type: 'bool'}) drawingIsActive: boolean; + @Column({type: 'time'}) drawingValidTill: string; + + @ManyToOne(type => CoordinateEntity, mapDrawings_coordinates => mapDrawings_coordinates.mapDrawings) + mapDrawings_coordinates: CoordinateEntity; + @ManyToOne(type => MapEntity, map => map.mapDrawings) + map: MapEntity; + @ManyToOne(type => MapDrawingTypeEntity, mapDrawingType => mapDrawingType.mapDrawings) + mapDrawingType: MapEntity; + @ManyToOne(type => FactionEntity, faction => faction.mapDrawings) + faction: FactionEntity; +} + +@Entity('MapDrawingType') +export class MapDrawingTypeEntity { + @PrimaryGeneratedColumn('uuid') mapDrawingTypeId: string; + @Column({type: 'text'}) drawingTypeName: string; + @Column({type: 'text'}) drawingTypeDescription: string; + + @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawingType) + mapDrawings: MapDrawingEntity[]; } \ No newline at end of file diff --git a/src/game/game.service.ts b/src/game/game.service.ts index 2d06c62..a3400df 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -38,14 +38,14 @@ export class GameService { } // edit already created game - async editGame(gameId: string, gameData: Partial<CreateGameDTO>) { + async editGame(id: string, gameData: Partial<GameDTO>) { try { // update game entry in db let update = await this.gameRepository.create({ ...gameData, factions: gameData.factions }) - await this.gameRepository.update({ gameId }, update); + await this.gameRepository.update({ id }, update); // add the factions to db if (gameData.factions) { gameData.factions.map(async faction => { @@ -62,9 +62,9 @@ export class GameService { } catch (error) {console.log(error)} } - async deleteGame(gameId) { + async deleteGame(id) { // TODO: Delete factions from Faction table associated with the deleted game - await this.gameRepository.delete({ gameId }); + await this.gameRepository.delete({ id }); return { message: 'Game deleted', }; @@ -77,7 +77,7 @@ export class GameService { }); const game = await this.gameRepository.findOne({ where: { id: gameId } }); - const index = game.passwords.indexOf(json.password); + //const index = game.passwords.indexOf(json.password); // create game_Person entry /* const gamePerson = await this.game_PersonRepository.create({ -- GitLab