Skip to content
Snippets Groups Projects
Commit a08ccea1 authored by Ronnie Friman's avatar Ronnie Friman
Browse files

update logic

parent b5ab31c0
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm';
import { GameEntity } from '../game/game.entity';
import { FactionEntity } from '../faction/faction.entity';
import { DataDTO } from './mapdrawing.dto';
///////////////////////////////////////////////////////////////////////////
/// MapDrawingEntity & MapDrawingHistoryEntity reflect database tables. ///
......@@ -13,7 +14,7 @@ import { FactionEntity } from '../faction/faction.entity';
export class MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingId: string;
@Column({ type: 'bool', nullable: true }) drawingIsActive: boolean;
@Column({ type: 'json', nullable: true }) data: JSON;
@Column({ type: 'json', nullable: true }) data: DataDTO;
// When Faction or game that has the drawing in question is deleted from
// the database, the drawing is also deleted
......
......@@ -4,7 +4,6 @@ import {
Get,
Param,
UsePipes,
ValidationPipe,
Body,
UseInterceptors,
ClassSerializerInterceptor,
......@@ -14,6 +13,7 @@ import { DrawService } from './draw.service';
import { Roles, GameStates } from '../shared/guard.decorator';
import { MapDrawingDTO } from './mapdrawing.dto';
import { GamePerson } from '../game/gameperson.decorator';
import { ValidationPipe } from '../shared/validation.pipe';
//////////////////////////////////////////////////////////////////////////
/// DrawController ///
......
import { IsUUID, IsOptional, IsBoolean, Allow } from 'class-validator';
import {
IsUUID,
IsOptional,
IsBoolean,
IsHexColor,
ValidateNested,
IsArray,
IsNotEmpty,
IsString,
} from 'class-validator';
import { GameEntity } from '../game/game.entity';
import { Type } from 'class-transformer';
export class DataDTO {
@IsArray()
coordinates: number[];
@IsString()
type: string;
@IsOptional()
@IsHexColor()
colour: string;
@IsOptional()
radius: number;
@IsOptional()
text: string;
}
export class MapDrawingDTO {
@IsOptional()
@IsUUID('4')
mapDrawingId: string;
@Allow()
data: JSON;
@IsNotEmpty()
@ValidateNested()
@Type(() => DataDTO)
data: DataDTO;
@IsOptional()
@IsUUID('4')
gameId: GameEntity;
......
......@@ -15,11 +15,38 @@ import {
import { ObjectivePointEntity } from './game.entity';
import { FactionDTO } from '../faction/faction.dto';
import { CenterDTO, NodeSettingsDTO } from './game.json.dto';
import { Type } from 'class-transformer';
export class NodeCoreSettingsDTO {
@IsNumber()
capture_time: number;
@IsNumber()
confirmation_time: number;
@IsNumber()
owner: number;
@IsNumber()
capture: number;
@IsNumber()
buttons_available: number;
@IsNumber()
heartbeat_interval: number;
}
export class CenterDTO {
@IsNumber()
lat: number;
@IsNumber()
lng: number;
}
export class NodeSettingsDTO {
@ValidateNested()
@Type(() => NodeCoreSettingsDTO)
node_settings: NodeCoreSettingsDTO;
}
export class GameDTO {
@IsOptional()
@IsUUID('4')
id: string;
@IsString()
@IsNotEmpty()
......
......@@ -9,12 +9,11 @@ import {
JoinColumn,
} from 'typeorm';
import { MapDrawingEntity } from '../draw/coordinate.entity';
import { PersonEntity } from '../user/user.entity';
import { GameGroupEntity } from '../faction/faction.entity';
import { FactionEntity } from '../faction/faction.entity';
import { TaskEntity } from '../task/task.entity';
import { CenterDTO, NodeSettingsDTO } from './game.json.dto';
import { CenterDTO, NodeSettingsDTO } from './game.dto';
// table that stores all created games
@Entity('Game')
......
import { IsNumber } from 'class-validator';
export class NodeCoreSettingsDTO {
@IsNumber()
capture_time: number;
@IsNumber()
confirmation_time: number;
@IsNumber()
owner: number;
@IsNumber()
capture: number;
@IsNumber()
buttons_available: number;
@IsNumber()
heartbeat_interval: number;
}
import { IsNumber, ValidateNested } from 'class-validator';
import { NodeCoreSettingsDTO } from './game.json-nested.dto';
import { Type } from 'class-transformer';
export class CenterDTO {
@IsNumber()
lat: number;
@IsNumber()
lng: number;
}
export class NodeSettingsDTO {
@ValidateNested()
@Type(() => NodeCoreSettingsDTO)
node_settings: NodeCoreSettingsDTO;
}
import {
Injectable,
NestInterceptor,
ExecutionContext,
CallHandler,
Logger,
} from '@nestjs/common';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
/*
@Injectable()
export class LoggingInterceptor implements NestInterceptor {
intercept(
context: ExecutionContext,
next: CallHandler,
): Observable<any> {
const req = context.switchToHttp().getRequest();
const method = req.method;
const url = req.url;
const now = Date.now();
return next.handle().pipe(
tap(() => Logger.log(
`${method} ${url} ${Date.now() - now}ms`,
`${context.getClass().name}.${context.getHandler().name}`
))
)
}
}*/
......@@ -43,7 +43,6 @@ export class TickService {
this.logger.log('Ticking');
let games = await this.listGames();
games.map(game => {
this.logger.log(game);
this.scoreService.scoreTick(game.id);
});
};
......
import { IsNumber, Min, Max, Allow } from 'class-validator';
// latitude and longitude accepts degrees from worldmap
export class GeoDTO {
@IsNumber()
@Min(-90)
@Max(90)
lat: number;
@IsNumber()
@Min(-180)
@Max(180)
lng: number;
@Allow()
time: number;
}
import {
Controller,
Post,
Param,
UsePipes,
Body,
Get,
UseInterceptors,
ClassSerializerInterceptor,
} from '@nestjs/common';
import { Controller, Post, Param, UsePipes, Body, Get } from '@nestjs/common';
import { TrackingService } from './tracking.service';
import { User } from '../user/user.decorator';
import { Roles, GameStates } from '../shared/guard.decorator';
import { ValidationPipe } from '../shared/validation.pipe';
import { GeoDTO } from './geo.dto';
import { GamePerson } from '../game/gameperson.decorator';
import { GeoDTO } from './tracking.dto';
@Controller('tracking')
export class TrackingController {
......
import { ValidateNested } from 'class-validator';
import { GeoDTO } from './geo.dto';
import { IsNumber, Min, Max, Allow, ValidateNested } from 'class-validator';
import { Type } from 'class-transformer';
// latitude and longitude accepts degrees from worldmap
export class GeoDTO {
@IsNumber()
@Min(-90)
@Max(90)
lat: number;
@IsNumber()
@Min(-180)
@Max(180)
lng: number;
@Allow()
time: number;
}
export class TrackingDTO {
@ValidateNested()
@Type(() => GeoDTO)
......
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