Skip to content
Snippets Groups Projects
Commit 8d6e7d46 authored by L4072's avatar L4072
Browse files

Merge conflicts fixed

parent 9d634262
No related branches found
No related tags found
3 merge requests!59Development to master,!14Type orm,!13Type orm
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 { GameService } from './game.service';
import { AuthGuard } from '../shared/auth.guard'; import { AuthGuard } from '../shared/auth.guard';
...@@ -13,14 +13,14 @@ export class GameController { ...@@ -13,14 +13,14 @@ export class GameController {
@Post('new') @Post('new')
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @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); return this.gameservice.createNewGame(person, body);
} }
@Put(':id') @Put(':id')
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @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); return this.gameservice.editGame(id, body);
} }
......
import { IsNotEmpty, IsString, IsDate, Length, IsInt, Min, Max, IsArray, IsJSON } from 'class-validator'; import { IsNotEmpty, IsString, IsDate, Length, IsInt, Min, Max, IsArray, IsJSON } from 'class-validator';
import { Timestamp } from 'typeorm'; import { Timestamp } from 'typeorm';
export class CreateGameDTO { export class GameDTO {
@IsString() @IsNotEmpty() @Length(3, 30) @IsString() @IsNotEmpty() @Length(3, 30)
gameName: string; name: string;
@IsString() @IsString()
gameDescription?: string; gameDescription?: string;
......
...@@ -5,8 +5,9 @@ import { ...@@ -5,8 +5,9 @@ import {
ManyToOne, ManyToOne,
OneToMany, OneToMany,
Timestamp, Timestamp,
PrimaryColumn,
} from 'typeorm'; } from 'typeorm';
import { PersonEntity } from 'src/user/user.entity'; import { PersonEntity, PersonRoleEntity } from 'src/user/user.entity';
// table that stores all created games // table that stores all created games
@Entity('Game') @Entity('Game')
...@@ -18,12 +19,15 @@ export class GameEntity { ...@@ -18,12 +19,15 @@ export class GameEntity {
@Column('json') map: JSON; @Column('json') map: JSON;
@Column('timestamp') startdate: Timestamp; @Column('timestamp') startdate: Timestamp;
@Column('timestamp') enddate: 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) @OneToMany(type => FactionEntity, faction => faction.game)
factions: FactionEntity[]; factions: FactionEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.game) @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
game_persons: Game_PersonEntity[]; game_persons: Game_PersonEntity[];
@OneToMany(type => ObjectivePointEntity, objective_points => objective_points.game)
objective_points: ObjectivePointEntity[];
gameObject() { gameObject() {
const { id, name } = this; const { id, name } = this;
...@@ -31,18 +35,6 @@ export class GameEntity { ...@@ -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 // table that stores players associated with particular game
@Entity('Game_Person') @Entity('Game_Person')
export class Game_PersonEntity { export class Game_PersonEntity {
...@@ -81,4 +73,148 @@ export class ObjectivePoint_HistoryEntity { ...@@ -81,4 +73,148 @@ export class ObjectivePoint_HistoryEntity {
@ManyToOne(type => ObjectivePointEntity, objective_point => objective_point.op_history) @ManyToOne(type => ObjectivePointEntity, objective_point => objective_point.op_history)
objective_point: ObjectivePointEntity; 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
...@@ -38,14 +38,14 @@ export class GameService { ...@@ -38,14 +38,14 @@ export class GameService {
} }
// edit already created game // edit already created game
async editGame(gameId: string, gameData: Partial<CreateGameDTO>) { async editGame(id: string, gameData: Partial<GameDTO>) {
try { try {
// update game entry in db // update game entry in db
let update = await this.gameRepository.create({ let update = await this.gameRepository.create({
...gameData, ...gameData,
factions: gameData.factions factions: gameData.factions
}) })
await this.gameRepository.update({ gameId }, update); await this.gameRepository.update({ id }, update);
// add the factions to db // add the factions to db
if (gameData.factions) { if (gameData.factions) {
gameData.factions.map(async faction => { gameData.factions.map(async faction => {
...@@ -62,9 +62,9 @@ export class GameService { ...@@ -62,9 +62,9 @@ export class GameService {
} catch (error) {console.log(error)} } catch (error) {console.log(error)}
} }
async deleteGame(gameId) { async deleteGame(id) {
// TODO: Delete factions from Faction table associated with the deleted game // TODO: Delete factions from Faction table associated with the deleted game
await this.gameRepository.delete({ gameId }); await this.gameRepository.delete({ id });
return { return {
message: 'Game deleted', message: 'Game deleted',
}; };
...@@ -77,7 +77,7 @@ export class GameService { ...@@ -77,7 +77,7 @@ export class GameService {
}); });
const game = await this.gameRepository.findOne({ where: { id: gameId } }); 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 // create game_Person entry
/* const gamePerson = await this.game_PersonRepository.create({ /* const gamePerson = await this.game_PersonRepository.create({
......
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