import { Entity, Column, PrimaryGeneratedColumn, ManyToOne, OneToMany, Timestamp, OneToOne, JoinColumn, } from 'typeorm'; import { MapDrawingEntity } from '../draw/coordinate.entity'; import { PersonEntity } from '../user/user.entity'; import { GameGroupEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity'; import { TaskEntity } from '../task/task.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({ type: 'json', nullable: true }) nodesettings?: JSON; @Column('timestamp') startdate: Timestamp; @Column('timestamp') enddate: Timestamp; @OneToMany(type => FactionEntity, factions => factions.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[]; @OneToMany(type => TaskEntity, tasks => tasks.taskGame) tasks: TaskEntity[]; gameObject() { const { id, name } = this; return { id, name }; } } // table that stores players associated with particular game @Entity('Game_Person', { orderBy: { person: 'ASC', }, }) export class Game_PersonEntity { @PrimaryGeneratedColumn('uuid') gamepersonId: string; @Column({ type: 'text', nullable: true }) role: string; @ManyToOne(type => FactionEntity, faction => faction.game_persons) 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', }) 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('float') action: number; @ManyToOne(type => FactionEntity, factionEntity => factionEntity.factionId) capture: FactionEntity; @ManyToOne(type => FactionEntity, factionentity => factionentity.factionId) owner: FactionEntity; @ManyToOne( type => ObjectivePointEntity, objective_point => objective_point.objectivePointId, ) objective_point: ObjectivePointEntity; }