From 3068bef393e68c87838c766a56d188582a0103fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Syd=C3=A4nmaa?= <L4072@student.jamk.fi> Date: Fri, 7 Jun 2019 13:43:17 +0300 Subject: [PATCH] Database hiomista --- src/coordinate/coordinate.entity.ts | 51 +++++++++++++++++++++++++++-- src/game/faction.entity.ts | 8 +++-- src/game/game.controller.ts | 8 +++++ src/game/game.dto.ts | 9 +++++ src/game/game.entity.ts | 8 +++-- src/game/objectivepoint.entity.ts | 11 ------- 6 files changed, 77 insertions(+), 18 deletions(-) create mode 100644 src/game/game.controller.ts create mode 100644 src/game/game.dto.ts delete mode 100644 src/game/objectivepoint.entity.ts diff --git a/src/coordinate/coordinate.entity.ts b/src/coordinate/coordinate.entity.ts index 949de82..988b725 100644 --- a/src/coordinate/coordinate.entity.ts +++ b/src/coordinate/coordinate.entity.ts @@ -1,6 +1,7 @@ -import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, ManyToMany, OneToMany } from 'typeorm'; -import {Game_PersonEntity, ObjectivePointEntity} from '../game/game.entity' - +import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, ManyToMany, OneToMany, ManyToOne, JoinTable } from 'typeorm'; +import {Game_PersonEntity, ObjectivePointEntity, GameEntity} from '../game/game.entity' +import { FactionEntity } from '../game/faction.entity' +//import { MapEntity, MapDrawingEntity } from '../map/map.entity' @Entity('Coordinate') export class CoordinateEntity { @@ -8,8 +9,52 @@ export class CoordinateEntity { @Column({type: 'geometry'}) longitude: string; @Column({type: 'geometry'}) latitude: string; + @ManyToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.mapDrawings_coordinates) + mapDrawings: MapDrawingEntity[]; @ManyToMany(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; + + @ManyToMany(type => CoordinateEntity, mapDrawings_coordinates => mapDrawings_coordinates.mapDrawings) + @JoinTable() + 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 index aa56542..0c79ee2 100644 --- a/src/game/faction.entity.ts +++ b/src/game/faction.entity.ts @@ -1,14 +1,16 @@ -import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToMany, JoinTable, ManyToOne, Timestamp } from 'typeorm'; -import { type } from 'os'; +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/coordinate.entity' @Entity('Faction') export class FactionEntity { @PrimaryGeneratedColumn('uuid') factionId: string; @Column({type: 'text', unique: true}) factionName: string; + @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction) + mapDrawings: MapDrawingEntity[]; @OneToMany(type => ScoreEntity, scores => scores.faction) scores: ScoreEntity[]; @OneToMany(type => PowerUpEntity, powerUps => powerUps.factions) @@ -70,6 +72,8 @@ 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; diff --git a/src/game/game.controller.ts b/src/game/game.controller.ts new file mode 100644 index 0000000..aec0681 --- /dev/null +++ b/src/game/game.controller.ts @@ -0,0 +1,8 @@ +import { Controller, Post, Body } from '@nestjs/common'; +import {CreateGameDTO} from './game.dto' + +@Controller('Game') +export class GameController{ + //@Post() + //create(@Body() ) +} \ No newline at end of file diff --git a/src/game/game.dto.ts b/src/game/game.dto.ts new file mode 100644 index 0000000..664739c --- /dev/null +++ b/src/game/game.dto.ts @@ -0,0 +1,9 @@ +import { IsNotEmpty, IsString } from 'class-validator'; + +export class CreateGameDTO { + @IsString () @IsNotEmpty() + gameId: string; + + @IsString () @IsNotEmpty() + gameName: string; +} \ No newline at end of file diff --git a/src/game/game.entity.ts b/src/game/game.entity.ts index 6b4a8e8..26d09a4 100644 --- a/src/game/game.entity.ts +++ b/src/game/game.entity.ts @@ -1,7 +1,8 @@ -import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany, ManyToOne, ManyToMany, Timestamp } from 'typeorm'; +import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, ManyToMany, Timestamp, JoinTable } from 'typeorm'; import {PersonEntity, PersonRoleEntity} from '../user/user.entity' import {FactionEntity} from './faction.entity' import {CoordinateEntity} from '../coordinate/coordinate.entity' +import { MapEntity } from '../coordinate/coordinate.entity' @Entity('Game') export class GameEntity { @@ -11,6 +12,8 @@ export class GameEntity { @Column({type: 'date'}) startDate: string; @Column({type: 'date'}) endDate: string; + @ManyToOne(type => MapEntity, map => map.games) + map: MapEntity; @OneToMany(type => FactionEntity, faction => faction.game) factions: FactionEntity[]; @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game) @@ -33,6 +36,7 @@ export class Game_PersonEntity { @ManyToOne(type => PersonRoleEntity, person_role => person_role.game_persons) person_role: PersonRoleEntity; @ManyToMany(type => CoordinateEntity, game_person_coordinates => game_person_coordinates.game_persons) + @JoinTable() game_person_coordinates: CoordinateEntity[]; } @@ -53,7 +57,7 @@ export class ObjectivePointEntity { export class ObjectivePoint_HistoryEntity { @PrimaryGeneratedColumn('uuid') oP_HistoryId: string; @Column({type: 'timestamp'}) oP_HistoryTimestamp: Timestamp; - //@Column({/*type: 'timestamp'*/}) oP_HistoryStatus: Timestamp; + @Column({/*type: 'timestamp'*/}) oP_HistoryStatus: number; @ManyToOne(type => ObjectivePointEntity, objective_point => objective_point.op_history) objective_point: ObjectivePointEntity; diff --git a/src/game/objectivepoint.entity.ts b/src/game/objectivepoint.entity.ts deleted file mode 100644 index 5f0a81a..0000000 --- a/src/game/objectivepoint.entity.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert } from 'typeorm'; - -@Entity('ObjectivePoint') -export class ObjectivePointEntity { - @PrimaryGeneratedColumn('uuid') objectivePointId: string; - @Column({type: 'text'}) powerUpDescription: string; - @Column({type: 'int'}) amount: number; - @Column({type: 'time'}) cooldown: string; - //history; milloin käytetty (timestamp) taulukko - -} \ No newline at end of file -- GitLab