Skip to content
Snippets Groups Projects
Commit 9a4447d8 authored by L4072's avatar L4072
Browse files

Adds game controller and updates database

parent 3068bef3
No related branches found
No related tags found
4 merge requests!59Development to master,!14Type orm,!13Type orm,!11Type orm
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, ManyToMany, OneToMany, ManyToOne, JoinTable } from 'typeorm';
import {Game_PersonEntity, ObjectivePointEntity, GameEntity} from '../game/game.entity'
import { FactionEntity } from '../game/faction.entity'
import {Game_PersonEntity, ObjectivePointEntity, GameEntity} from './game.entity'
import { FactionEntity } from './faction.entity'
//import { MapEntity, MapDrawingEntity } from '../map/map.entity'
@Entity('Coordinate')
......
......@@ -2,12 +2,14 @@ import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, Timestamp
import {PersonEntity} from '../user/user.entity'
import {GameEntity} from './game.entity'
import {Game_PersonEntity} from './game.entity'
import { MapDrawingEntity } from '../coordinate/coordinate.entity'
import { MapDrawingEntity } from './coordinate.entity'
@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[];
......@@ -60,7 +62,7 @@ export class FP_HistoryEntity{
@Entity('Score')
export class ScoreEntity {
@PrimaryGeneratedColumn('uuid') scoreId: string;
@Column({type: 'int'}) score: number;
@Column({type: 'float'}) score: number;
@Column({type: 'timestamp'}) scoreTimeStamp: Timestamp;
@ManyToOne(type => FactionEntity, factionName => factionName.scores)
......
import { Controller, Post, Body } from '@nestjs/common';
import {CreateGameDTO} from './game.dto'
@Controller('Game')
@Controller('game')
export class GameController{
//@Post()
//create(@Body() )
@Post()
create(@Body() data: CreateGameDTO) {
return this//.gameService.register(data);
}
}
\ No newline at end of file
import { IsNotEmpty, IsString } from 'class-validator';
import { IsNotEmpty, IsString, IsDate, Length, IsInt, Min, Max, IsArray, IsJSON } from 'class-validator';
import { Timestamp } from 'typeorm';
import { FactionEntity } from './faction.entity';
export class CreateGameDTO {
@IsString () @IsNotEmpty()
@IsString() @IsNotEmpty()
gameId: string;
@IsString () @IsNotEmpty()
@IsString() @IsNotEmpty() @Length(3, 30)
gameName: string;
}
\ No newline at end of file
@IsString()
gameDescription?: string;
@IsDate() @IsNotEmpty()
startDate: string;
@IsDate() @IsNotEmpty()
endDate: string;
@IsArray() @IsNotEmpty()
factions?: FactionEntity[];
@IsArray() @IsNotEmpty()
powerUps?: PowerUpDTO[];
@IsArray() @IsNotEmpty()
objectivePoint?: ObjectivePointDTO[];
@IsJSON() @IsNotEmpty()
mapCoordinates: JSON;
@IsString() @IsNotEmpty() @Length(3, 255)
GM_Password?: string;
}
export class FactionDTO {
@IsString() @IsNotEmpty()
FactionID: string;
@IsString() @IsNotEmpty() @Length(3, 30)
FactionName: string;
}
export class PowerUpDTO {
@IsString() @IsNotEmpty()
powerUpName: string;
@IsString() @IsNotEmpty()
powerUpDescription?: string;
@IsInt() @IsNotEmpty()
amount: number;
@IsNotEmpty()
cooldown: string;
}
export class ObjectivePointDTO {
@IsString() @IsNotEmpty()
objectivePointID: string;
@IsString() @IsNotEmpty()
objectivePointDescription: string;
@IsJSON() @IsNotEmpty()
objectivePointCoordinates: JSON;
@IsArray() @IsNotEmpty()
objectivePointHistory: ObjectivePointHistoryDTO[];
}
export class ObjectivePointHistoryDTO {
@IsString()
FactionId: string;
@IsNotEmpty() @IsInt() @Min(0) @Max(2)
oP_HistoryStatus: number;
@IsNotEmpty()
oP_HistoryTimestamp: Timestamp;
}
import { Entity, Column, PrimaryGeneratedColumn, OneToMany, ManyToOne, ManyToMany, Timestamp, JoinTable } from 'typeorm';
import {PersonEntity, PersonRoleEntity} from '../user/user.entity'
import {FactionEntity} from './faction.entity'
import {CoordinateEntity} from '../coordinate/coordinate.entity'
import { MapEntity } from '../coordinate/coordinate.entity'
import {CoordinateEntity} from './coordinate.entity'
import { MapEntity } from './coordinate.entity'
@Entity('Game')
export class GameEntity {
......@@ -11,6 +11,7 @@ export class GameEntity {
@Column({type: 'text'}) gameDescription: string;
@Column({type: 'date'}) startDate: string;
@Column({type: 'date'}) endDate: string;
@Column({type: 'text'}) GM_Password: string;
@ManyToOne(type => MapEntity, map => map.games)
map: MapEntity;
......@@ -21,6 +22,10 @@ export class GameEntity {
@OneToMany(type => ObjectivePointEntity, objective_points => objective_points.game)
objective_points: ObjectivePointEntity[];
gameObject() {
const {gameId, gameName, gameDescription, startDate, endDate, GM_Password} = this;
return this;
}
}
@Entity('Game_Person')
......
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { Repository } from "typeorm";
import { InjectRepository } from "@nestjs/typeorm";
import { GameEntity } from './game.entity';
import { CreateGameDTO } from './game.dto';
@Injectable()
export class UserService {
constructor(@InjectRepository(GameEntity) private userRepository: Repository<GameEntity>){}
async register(data: CreateGameDTO) {
const { gameName } = data;
let user = await this.userRepository.findOne({where: {name}});
if (user) {
throw new HttpException('User already exists', HttpStatus.BAD_REQUEST);
}
user = await this.userRepository.create(data);
await this.userRepository.save(user);
return user.gameObject();
}
/*async login(data: UserDTO) {
const { name, password } = data;
const user = await this.userRepository.findOne({ where: { name }});
if (!user || !(await user.comparePassword(password))) {
throw new HttpException(
'Invalid username/password',
HttpStatus.BAD_REQUEST,
);
}
return user.tokenObject();
}*/
}
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