Newer
Older
import {
Entity,
Column,
PrimaryGeneratedColumn,
ManyToOne,
OneToMany,
Timestamp,
import { PersonEntity } from '../user/user.entity';
import { GameGroupEntity } from '../faction/faction.entity';
import { FactionEntity } from '../faction/faction.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({ type: 'json', nullable: true }) nodesettings?: NodeSettingsDTO;
@Column('timestamp') startdate: Timestamp;
@Column('timestamp') enddate: Timestamp;
@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',
},
})
@PrimaryGeneratedColumn('uuid') gamepersonId: string;
@Column({ type: 'text', nullable: true }) role: string;
// If a Faction or Game where the GamePerson was in is deleted, the GamePerson is also deleted
@ManyToOne(type => FactionEntity, faction => faction.game_persons, {
@ManyToOne(type => GameEntity, game => game.id, {
onDelete: 'CASCADE',
})
@ManyToOne(type => PersonEntity, person => person.id)
// When a Group where GamePerson is is deleted, nothing happens to the GamePerson
@ManyToOne(type => GameGroupEntity, group => group.players, {
@Entity('ObjectivePoint')
export class ObjectivePointEntity {
@PrimaryGeneratedColumn('uuid') objectivePointId: string;
@Column({ type: 'text' }) objectivePointDescription: string;
@Column({ type: 'float' }) objectivePointMultiplier: number;
@Column({ type: 'json' }) data: JSON;
// If the Game where the ObjectivePoint was in is deleted, the ObjectivePoint is also deleted
@ManyToOne(type => GameEntity, game => game.objective_points, {
onDelete: 'CASCADE',
})
@OneToMany(
() => ObjectivePoint_HistoryEntity,
history => history.objective_point,
{
onDelete: 'NO ACTION',
},
)
history: ObjectivePoint_HistoryEntity[];
}
@Entity('ObjectivePoint_History')
export class ObjectivePoint_HistoryEntity {
@PrimaryGeneratedColumn('uuid') oP_HistoryId: string;
@Column({ type: 'float' }) oP_HistoryTimestamp: number;
// If the owner Faction, capturer Faction or ObjectivePoint, that has, is trying to have or is the point where
// ObjectivePointHistory points to is deleted, the ObjectivePointHistory is also deleted
@ManyToOne(type => FactionEntity, factionEntity => factionEntity.factionId, {
onDelete: 'CASCADE',
})
@ManyToOne(type => FactionEntity, factionentity => factionentity.factionId, {
onDelete: 'CASCADE',
})
objective_point => objective_point.objectivePointId,