Skip to content
Snippets Groups Projects
game.entity.ts 848 B
Newer Older
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
  Timestamp,
} from 'typeorm';


// 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') map: JSON;
  @Column('timestamp') startdate: Timestamp;
  @Column('timestamp') enddate: Timestamp;
  @OneToMany(type => FactionEntity, faction => faction.game)
  factions: FactionEntity[];
L4168's avatar
L4168 committed

  gameObject() {
    const { id, name } = this;
    return { id, name };
  }
}

// table that stores all factions created for games
@Entity('Faction')
export class FactionEntity {
  @PrimaryGeneratedColumn('uuid') id: string;
  @Column('text') name: string;
  @ManyToOne(type => GameEntity, game => game.factions)
  game: GameEntity;
L4168's avatar
L4168 committed
}