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