Skip to content
Snippets Groups Projects
game.entity.ts 2.84 KiB
Newer Older
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
  Timestamp,
L4168's avatar
L4168 committed
  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';
Samuli Virtapohja's avatar
Samuli Virtapohja committed

// 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;
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  @Column({ type: 'json', nullable: true }) map: JSON;
  @Column('timestamp') startdate: Timestamp;
  @Column('timestamp') enddate: Timestamp;
L4072's avatar
L4072 committed
  @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[];
L4168's avatar
L4168 committed
  @OneToMany(
    type => ObjectivePointEntity,
    objective_points => objective_points.game,
  )
  objective_points: ObjectivePointEntity[];

L4168's avatar
L4168 committed
  gameObject() {
    const { id, name } = this;
    return { id, name };
  }
// table that stores players associated with particular game
@Entity('Game_Person')
export class Game_PersonEntity {
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  @PrimaryGeneratedColumn('uuid') gamepersonId: string;
  @Column({ type: 'text', nullable: true }) role: string;
  @ManyToOne(type => FactionEntity, faction => faction.factionId)
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  faction: FactionEntity;
  @ManyToOne(type => GameEntity, game => game.id)
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  game: GameEntity;
  @ManyToOne(type => PersonEntity, person => person.id)
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  person: PersonEntity;
L4168's avatar
L4168 committed
  @OneToOne(type => GameGroupEntity, group => group.leader, {
Samuli Virtapohja's avatar
Samuli Virtapohja committed
    onDelete: 'CASCADE',
L4168's avatar
L4168 committed
  })
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  @JoinColumn({ name: 'leaderGroup' })
  leaderGroup: GameGroupEntity;
L4168's avatar
L4168 committed
  @ManyToOne(type => GameGroupEntity, group => group.players, {
Samuli Virtapohja's avatar
Samuli Virtapohja committed
    onDelete: 'CASCADE',
L4168's avatar
L4168 committed
  })
Samuli Virtapohja's avatar
Samuli Virtapohja committed
  @JoinColumn({ name: 'group' })
  group: GameGroupEntity;
Samuli Virtapohja's avatar
Samuli Virtapohja committed
}
L4168's avatar
L4168 committed
@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,
L4168's avatar
L4168 committed
  )
  objective_point: ObjectivePointEntity;
}