Skip to content
Snippets Groups Projects
Commit 54ba2839 authored by L4168's avatar L4168
Browse files

refactoring database

parent ece5706d
No related branches found
No related tags found
2 merge requests!59Development to master,!18Join game
import {
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
ManyToOne,
PrimaryColumn,
Timestamp,
} from 'typeorm';
import {
Game_PersonEntity,
ObjectivePointEntity,
GameEntity,
} from './game.entity';
import { FactionEntity } from './faction.entity';
@Entity('MapDrawing')
export class MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingId: string;
@Column({ type: 'bool' }) drawingIsActive: boolean;
@Column({ type: 'time' }) drawingValidTill: string;
@Column({ type: 'json', nullable: true }) data: JSON;
@ManyToOne(type => FactionEntity, faction => faction.mapDrawings)
faction: FactionEntity;
@ManyToOne(type => GameEntity, gameEntity => gameEntity.id)
gameId: GameEntity;
}
\ No newline at end of file
import {
Entity,
Column,
PrimaryGeneratedColumn,
OneToMany,
ManyToOne,
Timestamp,
} from 'typeorm';
import { GameEntity } from './game.entity';
import { Game_PersonEntity } from './game.entity';
import { MapDrawingEntity } from './coordinate.entity';
//Faction, PowerUp, Faction_powerUp, FP_History, Score, Task
@Entity('Faction')
export class FactionEntity {
@PrimaryGeneratedColumn('uuid') factionId: string;
@Column({ type: 'text', unique: true }) factionName: string;
@Column({ type: 'text' }) factionPassword: string;
@Column({ type: 'float' }) multiplier: number;
@OneToMany(type => MapDrawingEntity, mapDrawings => mapDrawings.faction)
mapDrawings: MapDrawingEntity[];
@OneToMany(type => ScoreEntity, scores => scores.faction)
scores: ScoreEntity[];
@OneToMany(type => PowerUpEntity, powerUps => powerUps.factions)
powerUps: Faction_PowerUpEntity[];
@OneToMany(type => TaskEntity, tasks => tasks.faction)
tasks: TaskEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction)
game_persons: Game_PersonEntity[];
@ManyToOne(type => GameEntity, game => game.factions)
game: GameEntity;
}
@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.powerUps)
factions: Faction_PowerUpEntity[];
}
@Entity('Faction_PowerUp')
export class Faction_PowerUpEntity {
@PrimaryGeneratedColumn('uuid') faction_powerUpId: string;
@ManyToOne(type => FactionEntity, faction => faction.powerUps)
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.scores)
faction: FactionEntity;
}
@Entity('Task')
export class TaskEntity {
@PrimaryGeneratedColumn('uuid') taskId: string;
@Column({ type: 'text' }) taskName: string;
@Column({ type: 'text' }) taskDescription: string;
@Column({ type: 'text' }) taskWinner: string;
@Column({ type: 'bool' }) taskIsActive: boolean;
@ManyToOne(type => FactionEntity, faction => faction.tasks)
faction: FactionEntity;
/* @ManyToOne(type => PersonEntity, person => person.tasks)
person: PersonEntity; */
}
\ No newline at end of file
......@@ -6,10 +6,13 @@ import {
OneToMany,
Timestamp,
OneToOne,
JoinColumn,
} from 'typeorm';
import { PersonEntity } from '../user/user.entity';
import { GameGroupEntity } from './group.entity';
import { FactionEntity } from './faction.entity';
import { MapDrawingEntity } from './coordinate.entity';
// table that stores all created games
@Entity('Game')
......@@ -27,6 +30,12 @@ export class GameEntity {
game_persons: Game_PersonEntity[];
@OneToMany(type => GameGroupEntity, group => group.game)
groups: GameGroupEntity[];
@OneToMany(
type => ObjectivePointEntity,
objective_points => objective_points.game,
)
objective_points: ObjectivePointEntity[];
gameObject() {
const { id, name } = this;
......@@ -34,20 +43,6 @@ export class GameEntity {
}
}
// table that stores all factions created for games
@Entity('Faction')
export class FactionEntity {
@PrimaryGeneratedColumn('uuid') id: string;
@Column('text') name: string;
@Column('text') password: string;
@ManyToOne(type => GameEntity, game => game.factions)
game: GameEntity;
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.faction, {
onUpdate: 'CASCADE',
})
game_persons: Game_PersonEntity[];
}
// table that stores players associated with particular game
@Entity('Game_Person')
export class Game_PersonEntity {
......@@ -59,14 +54,44 @@ export class Game_PersonEntity {
game: GameEntity;
@ManyToOne(type => PersonEntity, person => person.game_persons)
person: PersonEntity;
@OneToOne(type => GameGroupEntity, group => group.leader)
@OneToOne(type => GameGroupEntity, group => group.leader, {
onDelete: 'CASCADE'
})
@JoinColumn({name: 'leaderGroup'})
leaderGroup: GameGroupEntity;
@ManyToOne(type => GameGroupEntity, group => group.players)
@ManyToOne(type => GameGroupEntity, group => group.players, {
onDelete: 'CASCADE'
})
@JoinColumn({name: 'group'})
group: GameGroupEntity;
/*
@ManyToOne(type => PersonRoleEntity, person_role => person_role.game_persons)
person_role: PersonRoleEntity;
@ManyToMany(type => CoordinateEntity, game_person_coordinates => game_person_coordinates.game_persons)
game_person_coordinates: CoordinateEntity[]; */
}
@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;
@OneToMany(
type => ObjectivePoint_HistoryEntity,
op_history => op_history.objective_point,
)
op_history: Game_PersonEntity[];
}
@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.op_history,
)
objective_point: ObjectivePointEntity;
}
......@@ -3,9 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { GameController } from './game.controller';
import { GameService } from './game.service';
import { GameEntity, FactionEntity, Game_PersonEntity } from './game.entity';
import { GameEntity, Game_PersonEntity } from './game.entity';
import { PersonEntity } from '../user/user.entity';
import { GameGroupEntity } from './group.entity';
import { FactionEntity } from './faction.entity';
@Module({
imports: [TypeOrmModule.forFeature([GameEntity, FactionEntity, Game_PersonEntity, PersonEntity, GameGroupEntity])],
......
......@@ -14,10 +14,14 @@ import { Game_PersonEntity, GameEntity } from './game.entity';
export class GameGroupEntity {
@PrimaryGeneratedColumn('uuid') id: string;
@Column('text') name: string;
@OneToOne(type => Game_PersonEntity, person => person.leaderGroup)
@JoinColumn({name:'leader'})
@OneToOne(type => Game_PersonEntity, person => person.leaderGroup, {
onDelete: 'CASCADE'
})
//@JoinColumn({name:'leader'})
leader: Game_PersonEntity;
@OneToMany(type => Game_PersonEntity, person => person.group)
@OneToMany(type => Game_PersonEntity, person => person.group, {
onDelete: 'CASCADE'
})
players: Game_PersonEntity[];
@ManyToOne(type => GameEntity, game => game.groups)
game: GameEntity;
......
import { Entity, Column, PrimaryGeneratedColumn, Timestamp, ManyToOne } from 'typeorm';
import { PersonEntity } from '../user/user.entity'
import { FactionEntity } from '../game/game.entity';
/*
Entity: MapMarker
- represents data that database contains on mapmarker
*/
@Entity('MapMarker')
export class MapMarkerEntity {
import {
Entity,
Column,
PrimaryGeneratedColumn,
Timestamp,
ManyToOne,
} from 'typeorm';
import { PersonEntity } from '../user/user.entity';
/*
Entity: MapMarker
- represents data that database contains on mapmarker
*/
@Entity('MapMarker')
export class MapMarkerEntity {
@PrimaryGeneratedColumn('uuid') id: string;
@Column({type: 'text'}) latitude: string;
@Column({type: 'text'}) longitude: string;
@Column({type: 'timestamp'}) timestamp: Timestamp;
@Column({type: 'json', nullable: true}) features: JSON;
@Column({ type: 'text', nullable: true }) latitude: string;
@Column({ type: 'text', nullable: true }) longitude: string;
@Column({ type: 'timestamp' }) timestamp: Timestamp;
@Column({ type: 'json', nullable: true }) features: JSON;
@ManyToOne(type => PersonEntity, player => player.markers)
player?: PersonEntity;
//@ManyToOne(type => FactionEntity)
}
\ No newline at end of file
player: PersonEntity;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment