Newer
Older
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { FactionEntity } from '../faction/faction.entity';
///////////////////////////////////////////////////////////////////////////
/// MapDrawingEntity & MapDrawingHistoryEntity reflect database tables. ///
/// ///
/// MapDrawing ownershipCheck checks users rights to MapDrawing ///
///////////////////////////////////////////////////////////////////////////
@Entity('MapDrawing')
export class MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingId: string;
@Column({ type: 'bool', nullable: true }) drawingIsActive: boolean;
// When Faction or game that has the drawing in question is deleted from
@ManyToOne(type => FactionEntity, faction => faction.mapDrawings, {
onDelete: 'CASCADE',
})
@ManyToOne(type => GameEntity, gameEntity => gameEntity.id, {
onDelete: 'CASCADE',
})
async ownershipCheck(factionEntity, role) {
if (role === 'admin') {
return factionEntity == this.faction;
} else {
return this.faction && factionEntity.factionId === this.faction.factionId
? true
: false;
}
}
@Entity('MapDrawingHistory')
export class MapDrawingHistoryEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingHistoryId: string;
@Column('bool') drawingIsActive: boolean;
@Column('json') data: JSON;