import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, OneToOne, Timestamp, } from 'typeorm'; import { GameEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity'; import { MapDrawingEntity } from '../draw/coordinate.entity'; //Faction, PowerUp, Faction_powerUp, FP_History, Score @Entity('Faction') export class FactionEntity { @PrimaryGeneratedColumn('uuid') factionId: string; @Column('text') factionName: string; @Column({ type: 'text' }) factionPassword: string; @Column({ type: 'float' }) multiplier: number; @OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction) game_persons: Game_PersonEntity[]; @ManyToOne(type => GameEntity, game => game.factions) game: GameEntity; @OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction) mapDrawings: MapDrawingEntity[]; factionObject() { const { factionId, factionName, game } = this; return { factionId, factionName, game }; } passwordCheck(pass: string) { return pass == this.factionPassword ? true : false; } } @Entity('PowerUp') export class PowerUpEntity { @PrimaryGeneratedColumn('uuid') powerUpId: string; @Column({ type: 'text' }) powerUpName: string; @Column({ type: 'text' }) powerUpDescription: string; @Column({ type: 'int' }) amount: number; @Column({ type: 'time' }) cooldown: string; @OneToMany(type => FactionEntity, factions => factions.factionId) factions: Faction_PowerUpEntity[]; } @Entity('Faction_PowerUp') export class Faction_PowerUpEntity { @PrimaryGeneratedColumn('uuid') faction_powerUpId: string; @ManyToOne(type => FactionEntity, faction => faction.factionId) faction: FactionEntity; @ManyToOne(type => PowerUpEntity, powerUp => powerUp.factions) powerUp: PowerUpEntity; @OneToMany(type => FP_HistoryEntity, histories => histories.faction_PowerUp) histories: FP_HistoryEntity[]; } @Entity('FP_History') export class FP_HistoryEntity { @PrimaryGeneratedColumn('uuid') historyId: string; @Column({ type: 'timestamp' }) historyTimeStamp: Timestamp; @ManyToOne( type => Faction_PowerUpEntity, faction_PowerUp => faction_PowerUp.histories, ) faction_PowerUp: Faction_PowerUpEntity; } @Entity('Score') export class ScoreEntity { @PrimaryGeneratedColumn('uuid') scoreId: string; @Column({ type: 'float' }) score: number; @Column({ type: 'timestamp' }) scoreTimeStamp: Timestamp; @ManyToOne(type => FactionEntity, factionName => factionName.factionId) faction: FactionEntity; } @Entity('GameGroup') export class GameGroupEntity { @PrimaryGeneratedColumn('uuid') id: string; @Column('text') name: string; @OneToOne(type => Game_PersonEntity, person => person.leaderGroup, { onDelete: 'CASCADE', }) //@JoinColumn({name:'leader'}) leader: Game_PersonEntity; @OneToMany(type => Game_PersonEntity, person => person.group, { onDelete: 'CASCADE', }) players: Game_PersonEntity[]; @ManyToOne(type => GameEntity, game => game.groups) game: GameEntity; }