Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • wimma-lab-2019/overflow/ehasa-backend
1 result
Show changes
Commits on Source (12)
...@@ -3090,8 +3090,7 @@ ...@@ -3090,8 +3090,7 @@
"ansi-regex": { "ansi-regex": {
"version": "2.1.1", "version": "2.1.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"aproba": { "aproba": {
"version": "1.2.0", "version": "1.2.0",
...@@ -3112,14 +3111,12 @@ ...@@ -3112,14 +3111,12 @@
"balanced-match": { "balanced-match": {
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"brace-expansion": { "brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"balanced-match": "^1.0.0", "balanced-match": "^1.0.0",
"concat-map": "0.0.1" "concat-map": "0.0.1"
...@@ -3134,20 +3131,17 @@ ...@@ -3134,20 +3131,17 @@
"code-point-at": { "code-point-at": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"concat-map": { "concat-map": {
"version": "0.0.1", "version": "0.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"console-control-strings": { "console-control-strings": {
"version": "1.1.0", "version": "1.1.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"core-util-is": { "core-util-is": {
"version": "1.0.2", "version": "1.0.2",
...@@ -3264,8 +3258,7 @@ ...@@ -3264,8 +3258,7 @@
"inherits": { "inherits": {
"version": "2.0.3", "version": "2.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"ini": { "ini": {
"version": "1.3.5", "version": "1.3.5",
...@@ -3277,7 +3270,6 @@ ...@@ -3277,7 +3270,6 @@
"version": "1.0.0", "version": "1.0.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"number-is-nan": "^1.0.0" "number-is-nan": "^1.0.0"
} }
...@@ -3292,7 +3284,6 @@ ...@@ -3292,7 +3284,6 @@
"version": "3.0.4", "version": "3.0.4",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"brace-expansion": "^1.1.7" "brace-expansion": "^1.1.7"
} }
...@@ -3300,14 +3291,12 @@ ...@@ -3300,14 +3291,12 @@
"minimist": { "minimist": {
"version": "0.0.8", "version": "0.0.8",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"minipass": { "minipass": {
"version": "2.3.5", "version": "2.3.5",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"safe-buffer": "^5.1.2", "safe-buffer": "^5.1.2",
"yallist": "^3.0.0" "yallist": "^3.0.0"
...@@ -3326,7 +3315,6 @@ ...@@ -3326,7 +3315,6 @@
"version": "0.5.1", "version": "0.5.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"minimist": "0.0.8" "minimist": "0.0.8"
} }
...@@ -3407,8 +3395,7 @@ ...@@ -3407,8 +3395,7 @@
"number-is-nan": { "number-is-nan": {
"version": "1.0.1", "version": "1.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"object-assign": { "object-assign": {
"version": "4.1.1", "version": "4.1.1",
...@@ -3420,7 +3407,6 @@ ...@@ -3420,7 +3407,6 @@
"version": "1.4.0", "version": "1.4.0",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"wrappy": "1" "wrappy": "1"
} }
...@@ -3506,8 +3492,7 @@ ...@@ -3506,8 +3492,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.2", "version": "5.1.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"safer-buffer": { "safer-buffer": {
"version": "2.1.2", "version": "2.1.2",
...@@ -3543,7 +3528,6 @@ ...@@ -3543,7 +3528,6 @@
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"code-point-at": "^1.0.0", "code-point-at": "^1.0.0",
"is-fullwidth-code-point": "^1.0.0", "is-fullwidth-code-point": "^1.0.0",
...@@ -3563,7 +3547,6 @@ ...@@ -3563,7 +3547,6 @@
"version": "3.0.1", "version": "3.0.1",
"bundled": true, "bundled": true,
"dev": true, "dev": true,
"optional": true,
"requires": { "requires": {
"ansi-regex": "^2.0.0" "ansi-regex": "^2.0.0"
} }
...@@ -3607,14 +3590,12 @@ ...@@ -3607,14 +3590,12 @@
"wrappy": { "wrappy": {
"version": "1.0.2", "version": "1.0.2",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
}, },
"yallist": { "yallist": {
"version": "3.0.3", "version": "3.0.3",
"bundled": true, "bundled": true,
"dev": true, "dev": true
"optional": true
} }
} }
}, },
......
import {
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
ManyToOne,
PrimaryColumn,
} from 'typeorm';
import {
Game_PersonEntity,
ObjectivePointEntity,
GameEntity,
} from './game.entity';
import { FactionEntity } from './faction.entity';
@Entity('Coordinate')
export class CoordinateEntity {
@PrimaryColumn('uuid') id: string;
@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.map)
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[];
}
import {
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
ManyToOne,
Timestamp,
} from 'typeorm';
import { PersonEntity } from '../user/user.entity';
import { GameEntity } from './game.entity';
import { Game_PersonEntity } from './game.entity';
import { MapDrawingEntity } from './coordinate.entity';
//Faction, PowerUp, Faction_powerUp, FP_History, Score, Task
@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;
}
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';
...@@ -21,7 +21,13 @@ export class GameController { ...@@ -21,7 +21,13 @@ export class GameController {
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
@UsePipes(new ValidationPipe()) @UsePipes(new ValidationPipe())
async editGame(@Param('id') id: string, @Body() body: GameDTO) { async editGame(@Param('id') id: string, @Body() body: GameDTO) {
return this.gameservice.editGame(body); return this.gameservice.editGame(id, body);
}
@Delete(':id')
@UseGuards(new AuthGuard())
async deleteGame(@Param('id') id) {
return this.gameservice.deleteGame(id);
} }
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
......
import { import {
IsString,
IsDateString,
IsJSON,
IsNotEmpty, IsNotEmpty,
IsString,
IsDate,
Length, Length,
IsInt,
Min,
Max,
IsArray, IsArray,
Validate, IsJSON,
} from 'class-validator'; } from 'class-validator';
import { ArrayLength } from 'src/shared/array-validation'; import { Timestamp } from 'typeorm';
export class GameDTO { export class GameDTO {
// uses class-validator built in validations
// see https://github.com/typestack/class-validator
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@Length(2, 31) @Length(3, 30)
name: string; name: string;
@IsString() @IsString()
gameDescription?: string;
@IsDate()
@IsNotEmpty() @IsNotEmpty()
@Length(1, 255) startDate: string;
desc: string;
center: JSON; @IsDate()
//@IsJSON()
// doesn't accept with IsJSON, WIP to get validation for map
map?: JSON;
@IsDateString()
@IsNotEmpty()
startdate: string;
@IsDateString()
@IsNotEmpty() @IsNotEmpty()
enddate: string; endDate: string;
@IsArray() @IsArray()
@IsNotEmpty() @IsNotEmpty()
@Length(5, 15, {
each: true,
})
// custom validation for array length (arr>min, arr<max)
//@Validate(ArrayLength, [4, 8])
passwords: string[];
factions?: FactionDTO[]; factions?: FactionDTO[];
@IsArray()
@IsNotEmpty()
objectivePoint?: ObjectivePointDTO[];
@IsJSON()
@IsNotEmpty()
mapCoordinates: JSON;
} }
export class FactionDTO { export class FactionDTO {
@IsString() @IsString()
@IsNotEmpty() @IsNotEmpty()
@Length(2, 15) @Length(3, 30)
name: string; factionName: string;
id: string;
game: GameDTO; @IsString()
@IsNotEmpty()
@Length(3, 255)
faction_Password?: string;
}
/*export class PowerUpDTO {
@IsString() @IsNotEmpty()
powerUpName: string;
@IsString() @IsNotEmpty()
powerUpDescription?: string;
@IsInt() @IsNotEmpty()
amount: number;
@IsNotEmpty()
cooldown: string;
}*/
export class ObjectivePointDTO {
@IsString()
@IsNotEmpty()
objectivePointDescription: string;
@IsJSON()
@IsNotEmpty()
objectivePointCoordinates: JSON;
@IsArray()
@IsNotEmpty()
objectivePointHistory: ObjectivePointHistoryDTO[];
}
export class ObjectivePointHistoryDTO {
@IsString()
factionId: string;
@IsNotEmpty()
@IsInt()
@Min(0)
@Max(2)
oP_HistoryStatus: number;
@IsNotEmpty()
oP_HistoryTimestamp: Timestamp;
} }
...@@ -5,8 +5,16 @@ import { ...@@ -5,8 +5,16 @@ import {
ManyToOne, ManyToOne,
OneToMany, OneToMany,
Timestamp, Timestamp,
PrimaryColumn,
} from 'typeorm'; } from 'typeorm';
import { PersonEntity } from 'src/user/user.entity'; import { PersonEntity, PersonRoleEntity } from '../user/user.entity';
import { FactionEntity } from '../game/faction.entity';
import {
CoordinateEntity,
MapEntity,
MapDrawingEntity,
MapDrawingTypeEntity,
} from './coordinate.entity';
// table that stores all created games // table that stores all created games
@Entity('Game') @Entity('Game')
...@@ -18,12 +26,18 @@ export class GameEntity { ...@@ -18,12 +26,18 @@ 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,32 +45,113 @@ export class GameEntity { ...@@ -31,32 +45,113 @@ export class GameEntity {
} }
} }
// table that stores all factions created for games // table that stores players associated with particular game
@Entity('Faction') @Entity('Game_Person')
export class FactionEntity { export class Game_PersonEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') gameId: string;
@Column('text') name: string; @ManyToOne(type => FactionEntity, faction => faction.game_persons)
@ManyToOne(type => GameEntity, game => game.factions) faction: FactionEntity;
@ManyToOne(type => GameEntity, game => game.game_persons)
game: GameEntity; game: GameEntity;
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) @ManyToOne(type => PersonEntity, person => person.game_persons)
game_persons: Game_PersonEntity[]; person: PersonEntity;
@ManyToOne(type => PersonRoleEntity, person_role => person_role.game_persons)
person_role: PersonRoleEntity;
@ManyToOne(
type => CoordinateEntity,
game_person_coordinates => game_person_coordinates.game_persons,
)
game_person_coordinates: CoordinateEntity;
}
@Entity('ObjectivePoint')
export class ObjectivePointEntity {
@PrimaryGeneratedColumn('uuid') objectivePointId: string;
@Column({ type: 'text' }) objectivePointDescription: string;
@Column({ type: 'float' }) objectivePointMultiplier: number;
@ManyToOne(
type => CoordinateEntity,
coordinate => coordinate.objective_points,
)
coordinate: CoordinateEntity;
@ManyToOne(type => GameEntity, game => game.objective_points)
game: GameEntity;
@OneToMany(
type => ObjectivePoint_HistoryEntity,
op_history => op_history.objective_point,
)
op_history: Game_PersonEntity[];
} }
// table that stores players associated with particular game @Entity('ObjectivePoint_History')
@Entity('Game_Person') export class ObjectivePoint_HistoryEntity {
export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') oP_HistoryId: string;
@PrimaryGeneratedColumn('uuid') gameId: string; @Column({ type: 'timestamp' }) oP_HistoryTimestamp: Timestamp;
@ManyToOne(type => FactionEntity, faction => faction.game_persons) @Column({}) oP_HistoryStatus: number;
faction: FactionEntity;
@ManyToOne(type => GameEntity, game => game.game_persons) @ManyToOne(
game: GameEntity; type => ObjectivePointEntity,
@ManyToOne(type => PersonEntity, person => person.game_persons) objective_point => objective_point.op_history,
person: PersonEntity; )
/* objective_point: ObjectivePointEntity;
@ManyToOne(type => PersonRoleEntity, person_role => person_role.game_persons) }
person_role: PersonRoleEntity;
@ManyToMany(type => CoordinateEntity, game_person_coordinates => game_person_coordinates.game_persons) @Entity('PowerUp')
game_person_coordinates: CoordinateEntity[]; */ 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;
}
...@@ -3,12 +3,20 @@ import { TypeOrmModule } from '@nestjs/typeorm'; ...@@ -3,12 +3,20 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { GameController } from './game.controller'; import { GameController } from './game.controller';
import { GameService } from './game.service'; import { GameService } from './game.service';
import { GameEntity, FactionEntity, Game_PersonEntity } from './game.entity'; import { GameEntity, Game_PersonEntity } from './game.entity';
import { PersonEntity } from 'src/user/user.entity'; import { FactionEntity } from './faction.entity';
import { PersonEntity } from '../user/user.entity';
@Module({ @Module({
imports: [TypeOrmModule.forFeature([GameEntity, FactionEntity, Game_PersonEntity, PersonEntity])], imports: [
TypeOrmModule.forFeature([
GameEntity,
FactionEntity,
Game_PersonEntity,
PersonEntity,
]),
],
controllers: [GameController], controllers: [GameController],
providers: [GameService] providers: [GameService],
}) })
export class GameModule {} export class GameModule {}
...@@ -2,7 +2,8 @@ import { Injectable, Logger, HttpException, HttpStatus } from '@nestjs/common'; ...@@ -2,7 +2,8 @@ import { Injectable, Logger, HttpException, HttpStatus } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository, In } from 'typeorm'; import { Repository, In } from 'typeorm';
import { GameEntity, FactionEntity, Game_PersonEntity } from './game.entity'; import { GameEntity, Game_PersonEntity } from './game.entity';
import { FactionEntity } from './faction.entity';
import { GameDTO } from './game.dto'; import { GameDTO } from './game.dto';
import { PersonEntity } from '../user/user.entity'; import { PersonEntity } from '../user/user.entity';
...@@ -33,29 +34,45 @@ export class GameService { ...@@ -33,29 +34,45 @@ export class GameService {
}); });
await this.gameRepository.insert(game); await this.gameRepository.insert(game);
return { return {
"message": "New game added" message: 'New game added',
}; };
} }
// edit already created game // edit already created game
async editGame(gamedata) { async editGame(id: string, gameData: Partial<GameDTO>) {
/* // get the id of the game created to pass it to factions table try {
const gameid = await this.gameRepository.findOne({ // update game entry in db
where: { name: gameData.name }, let update = await this.gameRepository.create({
}); ...gameData,
factions: gameData.factions,
gameData.factions.map(async faction => {
let name = await this.factionRepository.create({
...faction,
game: gameid,
}); });
await this.factionRepository.insert(name); await this.gameRepository.update({ id }, update);
}); */ // add the factions to db
return { if (gameData.factions) {
"message": "Game updated" gameData.factions.map(async faction => {
let name = await this.factionRepository.create({
...faction,
game: gameData,
});
await this.factionRepository.insert(name);
});
}
return {
message: 'Game updated',
};
} catch (error) {
console.log(error);
} }
} }
async deleteGame(id) {
// TODO: Delete factions from Faction table associated with the deleted game
await this.gameRepository.delete({ id });
return {
message: 'Game deleted',
};
}
// checks the password, creates an entry in GamePerson table with associated role&faction // checks the password, creates an entry in GamePerson table with associated role&faction
async joinGame(person, gameId, json) { async joinGame(person, gameId, json) {
const user = await this.personRepository.findOne({ const user = await this.personRepository.findOne({
...@@ -63,10 +80,10 @@ export class GameService { ...@@ -63,10 +80,10 @@ 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({
faction, faction,
gameId, gameId,
person, person,
......
...@@ -10,7 +10,7 @@ export class MapMarkersController { ...@@ -10,7 +10,7 @@ export class MapMarkersController {
constructor(private mapmarkerservice: MapMarkerService){} constructor(private mapmarkerservice: MapMarkerService){}
// Insert figure location, needs "authorization" header with valid Bearer token and content-type json // Insert figure location, needs "authorization" header with valid Bearer token and content-type json
@Put('insertLocation') @Put('insert-location')
@UseGuards(new AuthGuard()) @UseGuards(new AuthGuard())
async insertLocation(@User('id') person, @Body() data: MapMarkerDTO): Promise<string>{ async insertLocation(@User('id') person, @Body() data: MapMarkerDTO): Promise<string>{
try { try {
......
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany } from 'typeorm';
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
import { MapMarkerEntity } from 'src/mapmarkers/mapmarker.entity';
import { MapMarkerEntity } from '../mapmarkers/mapmarker.entity'; import {TaskEntity} from '../game/faction.entity'
import { Game_PersonEntity } from '../game/game.entity'; import {Game_PersonEntity} from '../game/game.entity'
@Entity('Person') @Entity('Person')
export class PersonEntity { export class PersonEntity {
...@@ -12,10 +12,11 @@ export class PersonEntity { ...@@ -12,10 +12,11 @@ export class PersonEntity {
@Column('text') password: string; @Column('text') password: string;
@OneToMany(type => MapMarkerEntity, marker => marker.player) @OneToMany(type => MapMarkerEntity, marker => marker.player)
markers: MapMarkerEntity[]; markers: MapMarkerEntity[];
@OneToMany(type => TaskEntity, task => task.person)
tasks: TaskEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.person) @OneToMany(type => Game_PersonEntity, game_persons => game_persons.person)
game_persons: Game_PersonEntity[]; game_persons: Game_PersonEntity[];
// hashes the password before inserting it to database // hashes the password before inserting it to database
@BeforeInsert() @BeforeInsert()
async hashPassword() { async hashPassword() {
...@@ -47,4 +48,13 @@ export class PersonEntity { ...@@ -47,4 +48,13 @@ export class PersonEntity {
{ expiresIn: '7d'}, { expiresIn: '7d'},
); );
} }
}
@Entity('PersonRole')
export class PersonRoleEntity {
@PrimaryGeneratedColumn('uuid') person_roleId: string;
@Column({type: 'text'}) person_roleDescription: string;
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.person_role)
game_persons: Game_PersonEntity[];
} }
\ No newline at end of file
...@@ -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])],
......