import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, OneToMany, Timestamp, OneToOne, JoinColumn, } from 'typeorm'; import { PersonEntity } from '../user/user.entity'; import { GameGroupEntity } from './group.entity'; import { FactionEntity, TaskEntity } from './faction.entity'; import { MapDrawingEntity, Game_Person_MapDrawingEntity } from './coordinate.entity'; // table that stores all created games @Entity('Game') export class GameEntity { @PrimaryGeneratedColumn('uuid') id: string; @Column('text') name: string; @Column('text') desc: string; @Column('json') center: JSON; @Column({ type: 'json', nullable: true }) map: JSON; @Column('timestamp') startdate: Timestamp; @Column('timestamp') enddate: Timestamp; @OneToMany(type => FactionEntity, factions => factions.factionId) factionsId: FactionEntity[]; @OneToMany(type => Game_PersonEntity, game_persons => game_persons.game) game_persons: Game_PersonEntity[]; @OneToMany(type => GameGroupEntity, group => group.game) groups: GameGroupEntity[]; @OneToMany( type => ObjectivePointEntity, objective_points => objective_points.game, ) objective_points: ObjectivePointEntity[]; gameObject() { const { id, name } = this; return { id, name }; } } // table that stores players associated with particular game @Entity('Game_Person') export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') gamepersonId: string; @Column({ type: 'text', nullable: true }) role: string; @ManyToOne(type => FactionEntity, faction => faction.factionId) faction: FactionEntity; @ManyToOne(type => GameEntity, game => game.id) game: GameEntity; @ManyToOne(type => PersonEntity, person => person.id) person: PersonEntity; @OneToOne(type => GameGroupEntity, group => group.leader, { onDelete: 'CASCADE', }) @JoinColumn({ name: 'leaderGroup' }) leaderGroup: GameGroupEntity; @ManyToOne(type => GameGroupEntity, group => group.players, { onDelete: 'CASCADE', }) @JoinColumn({ name: 'group' }) group: GameGroupEntity; } @Entity('ObjectivePoint') export class ObjectivePointEntity { @PrimaryGeneratedColumn('uuid') objectivePointId: string; @Column({ type: 'text' }) objectivePointDescription: string; @Column({ type: 'float' }) objectivePointMultiplier: number; @ManyToOne(type => MapDrawingEntity, coordinate => coordinate.data) coordinate: MapDrawingEntity; @ManyToOne(type => GameEntity, game => game.objective_points) game: GameEntity; } @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.objectivePointId, ) objective_point: ObjectivePointEntity; }