diff --git a/src/game/coordinate.entity.ts b/src/game/coordinate.entity.ts new file mode 100644 index 0000000000000000000000000000000000000000..ecaf6dd6ffa8953931747e32da5cc113fd04fa17 --- /dev/null +++ b/src/game/coordinate.entity.ts @@ -0,0 +1,56 @@ +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 diff --git a/src/game/faction.entity.ts b/src/game/faction.entity.ts new file mode 100644 index 0000000000000000000000000000000000000000..e5d8a740eea4e1e9e2a3fd30c5f42613d1a33c51 --- /dev/null +++ b/src/game/faction.entity.ts @@ -0,0 +1,86 @@ +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 diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts index 775d4945cdd697b6dcd8847a96011b0f26392b47..bba49166a663fa07bfa4bcb75fbd3239a401564f 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'; @@ -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()) diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts index 7a8b4935549afb7ccd53b1744a5929a566aa4f61..45904f64d9443789a12e0e57c6c3cc3c9dbf73b9 100644 --- a/src/game/game.dto.ts +++ b/src/game/game.dto.ts @@ -1,51 +1,98 @@ -import { - IsString, - IsDateString, - IsJSON, - IsNotEmpty, - Length, - IsArray, - Validate, -} from 'class-validator'; -import { ArrayLength } from 'src/shared/array-validation'; +import { IsNotEmpty, IsString, IsDate, Length, IsInt, Min, Max, IsArray, IsJSON } from 'class-validator'; +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) - name: string; - @IsString() - @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() - @IsNotEmpty() - 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[]; + @IsString() @IsNotEmpty() @Length(3, 30) + name: string; + + @IsString() + gameDescription?: string; + + @IsDate() @IsNotEmpty() + startDate: string; + + @IsDate() @IsNotEmpty() + endDate: string; + + @IsArray() @IsNotEmpty() + factions?: FactionDTO[]; + + @IsArray() @IsNotEmpty() + objectivePoint?: ObjectivePointDTO[]; + + @IsJSON() @IsNotEmpty() + mapCoordinates: JSON; + } +/*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 { - @IsString() - @IsNotEmpty() - @Length(2, 15) - name: string; - id: string; - game: GameDTO; + @IsString() @IsNotEmpty() @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; +} + diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index d7c42c9f27ba1cdb81cba0e74eaa88ce9b5f23d6..d4ffa1ad7766d939b10257d3a95f594f369a550a 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,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 -@Entity('Faction') +/*@Entity('Faction') export class FactionEntity { @PrimaryGeneratedColumn('uuid') id: string; @Column('text') name: string; @@ -41,22 +85,136 @@ export class FactionEntity { @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; } -// 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) +@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 => GameEntity, game => game.game_persons) - game: GameEntity; - @ManyToOne(type => PersonEntity, person => person.game_persons) + @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; - /* - @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 diff --git a/src/game/game.module.ts b/src/game/game.module.ts index e6a23cfabcf9fc4d8ed5d230e272ffe44448b025..1778eb7da38078ca011d5db8a2ad06a371d5def9 100644 --- a/src/game/game.module.ts +++ b/src/game/game.module.ts @@ -11,4 +11,4 @@ import { PersonEntity } from 'src/user/user.entity'; controllers: [GameController], providers: [GameService] }) -export class GameModule {} +export class GameModule {} \ No newline at end of file diff --git a/src/game/game.service.ts b/src/game/game.service.ts index b909d10acb9f0bbf3cb47bb462e5f0253ae4441d..a3400dfa4881453221797fec972b8de45b1fa3d1 100644 --- a/src/game/game.service.ts +++ b/src/game/game.service.ts @@ -38,22 +38,36 @@ export class GameService { } // 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 }, - }); + 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({ 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 => { - let name = await this.factionRepository.create({ - ...faction, - game: gameid, - }); - await this.factionRepository.insert(name); - }); */ + async deleteGame(id) { + // TODO: Delete factions from Faction table associated with the deleted game + await this.gameRepository.delete({ id }); return { - "message": "Game updated" - } + message: 'Game deleted', + }; } // checks the password, creates an entry in GamePerson table with associated role&faction @@ -63,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({ @@ -91,4 +105,4 @@ export class GameService { }); return game; } -} +} \ No newline at end of file diff --git a/src/mapmarkers/mapmarkers.controller.ts b/src/mapmarkers/mapmarkers.controller.ts index 09fa6761f12972a2bfb6ca9ec147ed7e8ab2c5be..58c4035753abd25239ba44623fb227d628c3c4d9 100644 --- a/src/mapmarkers/mapmarkers.controller.ts +++ b/src/mapmarkers/mapmarkers.controller.ts @@ -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 { diff --git a/src/user/user.entity.ts b/src/user/user.entity.ts index a71b569dc1434482557dc9701d2a644749081895..a1a33a09e6dad6fad6979a1ae7cf9ed270e0453f 100644 --- a/src/user/user.entity.ts +++ b/src/user/user.entity.ts @@ -1,9 +1,9 @@ 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 diff --git a/src/user/user.module.ts b/src/user/user.module.ts index 4776b01af4ef21f320506cd6b96a993d586a19e2..cd43a16b6f27fc11b6c277617f859889021b0c5a 100644 --- a/src/user/user.module.ts +++ b/src/user/user.module.ts @@ -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])],