Skip to content
Snippets Groups Projects
Commit 87f13e68 authored by L4721's avatar L4721
Browse files

Merge branch 'TypeORM' into 'Development'

Type orm

See merge request !14
parents 39308d36 8d6e7d46
No related branches found
No related tags found
2 merge requests!59Development to master,!14Type orm
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({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.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[];
}
\ No newline at end of file
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;
}
\ No newline at end of file
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 { IsNotEmpty, IsString, IsDate, Length, IsInt, Min, Max, IsArray, IsJSON } from 'class-validator';
IsString, import { Timestamp } from 'typeorm';
IsDateString,
IsJSON,
IsNotEmpty,
Length,
IsArray,
Validate,
} from 'class-validator';
import { ArrayLength } from 'src/shared/array-validation';
export class GameDTO { export class GameDTO {
// uses class-validator built in validations @IsString() @IsNotEmpty() @Length(3, 30)
// see https://github.com/typestack/class-validator name: string;
@IsString()
@IsNotEmpty() @IsString()
@Length(2, 31) gameDescription?: string;
name: string;
@IsString() @IsDate() @IsNotEmpty()
@IsNotEmpty() startDate: string;
@Length(1, 255)
desc: string; @IsDate() @IsNotEmpty()
center: JSON; endDate: string;
//@IsJSON()
// doesn't accept with IsJSON, WIP to get validation for map @IsArray() @IsNotEmpty()
map?: JSON; factions?: FactionDTO[];
@IsDateString()
@IsNotEmpty() @IsArray() @IsNotEmpty()
startdate: string; objectivePoint?: ObjectivePointDTO[];
@IsDateString()
@IsNotEmpty() @IsJSON() @IsNotEmpty()
enddate: string; mapCoordinates: JSON;
@IsArray()
@IsNotEmpty()
@Length(5, 15, {
each: true,
})
// custom validation for array length (arr>min, arr<max)
//@Validate(ArrayLength, [4, 8])
passwords: string[];
factions?: FactionDTO[];
} }
/*export class EditGameDTO {
@IsString() @IsNotEmpty() @Length(3, 30)
gameName?: string;
@IsString()
gameDescription?: string;
@IsDate() @IsNotEmpty()
startDate: string;
@IsDate() @IsNotEmpty()
endDate: string;
@IsArray() @IsNotEmpty()
factions?: FactionDTO[];
@IsArray() @IsNotEmpty()
objectivePoint?: ObjectivePointDTO[];
@IsJSON() @IsNotEmpty()
mapCoordinates: JSON;
@IsString() @IsNotEmpty() @Length(3, 255)
GM_Password?: string;
}*/
export class FactionDTO { export class FactionDTO {
@IsString() @IsString() @IsNotEmpty() @Length(3, 30)
@IsNotEmpty() factionName: string;
@Length(2, 15)
name: string; @IsString() @IsNotEmpty() @Length(3, 255)
id: string; faction_Password?: string;
game: GameDTO;
} }
/*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,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,8 +35,48 @@ export class GameEntity { ...@@ -31,8 +35,48 @@ export class GameEntity {
} }
} }
// 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;
@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[];
}
@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;
}
// table that stores all factions created for games // table that stores all factions created for games
@Entity('Faction') /*@Entity('Faction')
export class FactionEntity { export class FactionEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') id: string;
@Column('text') name: string; @Column('text') name: string;
...@@ -41,22 +85,136 @@ export class FactionEntity { ...@@ -41,22 +85,136 @@ export class FactionEntity {
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction)
game_persons: Game_PersonEntity[]; 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;
} }
// table that stores players associated with particular game @Entity('PowerUp')
@Entity('Game_Person') export class PowerUpEntity {
export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') powerUpId: string;
@PrimaryGeneratedColumn('uuid') gameId: string; @Column({type: 'text'}) powerUpName: string;
@ManyToOne(type => FactionEntity, faction => faction.game_persons) @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; faction: FactionEntity;
@ManyToOne(type => GameEntity, game => game.game_persons) @ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions)
game: GameEntity; powerUp: PowerUpEntity;
@ManyToOne(type => PersonEntity, person => person.game_persons) @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; 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('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
...@@ -11,4 +11,4 @@ import { PersonEntity } from 'src/user/user.entity'; ...@@ -11,4 +11,4 @@ import { PersonEntity } from 'src/user/user.entity';
controllers: [GameController], controllers: [GameController],
providers: [GameService] providers: [GameService]
}) })
export class GameModule {} export class GameModule {}
\ No newline at end of file
...@@ -38,22 +38,36 @@ export class GameService { ...@@ -38,22 +38,36 @@ export class GameService {
} }
// 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
})
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)}
}
gameData.factions.map(async faction => { async deleteGame(id) {
let name = await this.factionRepository.create({ // TODO: Delete factions from Faction table associated with the deleted game
...faction, await this.gameRepository.delete({ id });
game: gameid,
});
await this.factionRepository.insert(name);
}); */
return { return {
"message": "Game updated" 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
...@@ -63,7 +77,7 @@ export class GameService { ...@@ -63,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({
...@@ -91,4 +105,4 @@ export class GameService { ...@@ -91,4 +105,4 @@ export class GameService {
}); });
return game; return game;
} }
} }
\ No newline at end of file
...@@ -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])],
......
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