Skip to content
Snippets Groups Projects
Commit 691c2685 authored by L4072's avatar L4072
Browse files

Database Entities

parent 95452139
No related branches found
No related tags found
3 merge requests!14Type orm,!13Type orm,!11Type orm
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, ManyToMany, OneToMany } from 'typeorm';
import {Game_PersonEntity, ObjectivePointEntity} from '../game/game.entity'
@Entity('Coordinate')
export class CoordinateEntity {
@PrimaryGeneratedColumn('uuid') coordinateId: string;
@Column({type: 'geometry'}) longitude: string;
@Column({type: 'geometry'}) latitude: string;
@ManyToMany(type => Game_PersonEntity, game_persons => game_persons.game_person_coordinates)
game_persons: Game_PersonEntity[];
@OneToMany(type => ObjectivePointEntity, objective_points => objective_points.coordinate)
objective_points: ObjectivePointEntity[];
}
\ No newline at end of file
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToMany, JoinTable, ManyToOne, Timestamp } from 'typeorm';
import { type } from 'os';
import {PersonEntity} from '../user/user.entity'
import {GameEntity} from './game.entity'
import {Game_PersonEntity} from './game.entity'
@Entity('Faction')
export class FactionEntity {
@PrimaryGeneratedColumn('uuid') factionId: string;
@Column({type: 'text', unique: true}) factionName: string;
@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: 'int'}) 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;
@ManyToOne(type => FactionEntity, faction => faction.tasks)
faction: FactionEntity;
@ManyToOne(type => PersonEntity, person => person.tasks)
person: PersonEntity;
}
\ No newline at end of file
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany, ManyToOne, ManyToMany, Timestamp } from 'typeorm';
import {PersonEntity, PersonRoleEntity} from '../user/user.entity'
import {FactionEntity} from './faction.entity'
import {CoordinateEntity} from '../coordinate/coordinate.entity'
@Entity('Game')
export class GameEntity {
@PrimaryGeneratedColumn('uuid') gameId: string;
@Column({type: 'text', unique: true}) gameName: string;
@Column({type: 'text'}) gameDescription: string;
@Column({type: 'date'}) startDate: string;
@Column({type: 'date'}) endDate: string;
@OneToMany(type => FactionEntity, faction => faction.game)
factions: FactionEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.game)
game_persons: Game_PersonEntity[];
@OneToMany(type => ObjectivePointEntity, objective_points => objective_points.game)
objective_points: ObjectivePointEntity[];
}
@Entity('Game_Person')
export class Game_PersonEntity {
@PrimaryGeneratedColumn('uuid') gameId: string;
@ManyToOne(type => FactionEntity, faction => faction.game_persons)
faction: FactionEntity;
@ManyToOne(type => GameEntity, game => game.game_persons)
game: GameEntity;
@ManyToOne(type => PersonEntity, person => person.game_persons)
person: PersonEntity;
@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;
@ManyToOne(type => CoordinateEntity, coordinate => coordinate.objective_points)
coordinate: CoordinateEntity;
@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({/*type: 'timestamp'*/}) oP_HistoryStatus: Timestamp;
@ManyToOne(type => ObjectivePointEntity, objective_point => objective_point.op_history)
objective_point: ObjectivePointEntity;
}
\ No newline at end of file
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert } from 'typeorm';
@Entity('ObjectivePoint')
export class ObjectivePointEntity {
@PrimaryGeneratedColumn('uuid') objectivePointId: string;
@Column({type: 'text'}) powerUpDescription: string;
@Column({type: 'int'}) amount: number;
@Column({type: 'time'}) cooldown: string;
//history; milloin käytetty (timestamp) taulukko
}
\ No newline at end of file
...@@ -2,6 +2,8 @@ import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany } from ...@@ -2,6 +2,8 @@ import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, OneToMany } from
import * as bcrypt from 'bcryptjs'; import * as bcrypt from 'bcryptjs';
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
import { MapMarkerEntity } from 'src/mapmarkers/mapmarker.entity'; import { MapMarkerEntity } from 'src/mapmarkers/mapmarker.entity';
import {TaskEntity} from '../game/faction.entity'
import {Game_PersonEntity} from '../game/game.entity'
@Entity('Person') @Entity('Person')
export class PersonEntity { export class PersonEntity {
...@@ -10,6 +12,10 @@ export class PersonEntity { ...@@ -10,6 +12,10 @@ export class PersonEntity {
@Column('text') password: string; @Column('text') password: string;
@OneToMany(type => MapMarkerEntity, marker => marker.player) @OneToMany(type => MapMarkerEntity, marker => marker.player)
markers: MapMarkerEntity[]; markers: MapMarkerEntity[];
@OneToMany(type => TaskEntity, task => task.person)
tasks: TaskEntity[];
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.person)
game_persons: Game_PersonEntity[];
@BeforeInsert() @BeforeInsert()
async hashPassword() { async hashPassword() {
...@@ -40,4 +46,13 @@ export class PersonEntity { ...@@ -40,4 +46,13 @@ export class PersonEntity {
{ expiresIn: '7d'}, { expiresIn: '7d'},
); );
} }
}
@Entity('PersonRole')
export class PersonRoleEntity {
@PrimaryGeneratedColumn('uuid') person_roleId: string;
@Column({type: 'text'}) person_roleDescription: string;
@OneToMany(type => Game_PersonEntity, game_persons => game_persons.person_role)
game_persons: Game_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