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

added mapDrawingHistory for replay

parent 01d5aabc
No related branches found
No related tags found
3 merge requests!59Development to master,!44Development to testing,!42Draw update
import { Entity, Column, PrimaryGeneratedColumn, ManyToOne } from 'typeorm'; import {
Entity,
Column,
PrimaryGeneratedColumn,
ManyToOne,
CreateDateColumn,
} from 'typeorm';
import { GameEntity } from '../game/game.entity'; import { GameEntity } from '../game/game.entity';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
...@@ -7,8 +13,6 @@ import { FactionEntity } from '../faction/faction.entity'; ...@@ -7,8 +13,6 @@ import { FactionEntity } from '../faction/faction.entity';
export class MapDrawingEntity { export class MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingId: string; @PrimaryGeneratedColumn('uuid') mapDrawingId: string;
@Column({ type: 'bool', nullable: true }) drawingIsActive: boolean; @Column({ type: 'bool', nullable: true }) drawingIsActive: boolean;
@Column({ type: 'time', nullable: true }) drawingValidTill: string;
@Column({ type: 'json', nullable: true }) data: JSON; @Column({ type: 'json', nullable: true }) data: JSON;
@ManyToOne(type => FactionEntity, faction => faction.mapDrawings, { @ManyToOne(type => FactionEntity, faction => faction.mapDrawings, {
...@@ -30,3 +34,16 @@ export class MapDrawingEntity { ...@@ -30,3 +34,16 @@ export class MapDrawingEntity {
} }
} }
} }
@Entity('MapDrawingHistory')
export class MapDrawingHistoryEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingHistoryId: string;
@CreateDateColumn() timestamp: Date;
@Column('bool') drawingIsActive: boolean;
@Column('json') data: JSON;
@ManyToOne(() => MapDrawingEntity, mapDrawing => mapDrawing.mapDrawingId, {
onDelete: 'CASCADE',
})
mapdrawing: string;
}
...@@ -3,7 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm'; ...@@ -3,7 +3,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { DrawController } from './draw.controller'; import { DrawController } from './draw.controller';
import { DrawService } from './draw.service'; import { DrawService } from './draw.service';
import { MapDrawingEntity } from '../draw/coordinate.entity'; import {
MapDrawingEntity,
MapDrawingHistoryEntity,
} from '../draw/coordinate.entity';
import { FactionEntity } from '../faction/faction.entity'; import { FactionEntity } from '../faction/faction.entity';
import { Game_PersonEntity } from '../game/game.entity'; import { Game_PersonEntity } from '../game/game.entity';
import { NotificationModule } from 'src/notifications/notifications.module'; import { NotificationModule } from 'src/notifications/notifications.module';
...@@ -15,6 +18,7 @@ Draw ...@@ -15,6 +18,7 @@ Draw
imports: [ imports: [
TypeOrmModule.forFeature([ TypeOrmModule.forFeature([
MapDrawingEntity, MapDrawingEntity,
MapDrawingHistoryEntity,
FactionEntity, FactionEntity,
Game_PersonEntity, Game_PersonEntity,
]), ]),
......
...@@ -2,15 +2,20 @@ import { Injectable, HttpException, HttpStatus } from '@nestjs/common'; ...@@ -2,15 +2,20 @@ import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm'; import { Repository } from 'typeorm';
import { MapDrawingEntity } from '../draw/coordinate.entity'; import {
MapDrawingEntity,
MapDrawingHistoryEntity,
} from '../draw/coordinate.entity';
import { MapDrawingDTO } from './mapdrawing.dto'; import { MapDrawingDTO } from './mapdrawing.dto';
import { NotificationGateway } from 'src/notifications/notifications.gateway'; import { NotificationGateway } from '../notifications/notifications.gateway';
@Injectable() @Injectable()
export class DrawService { export class DrawService {
constructor( constructor(
@InjectRepository(MapDrawingEntity) @InjectRepository(MapDrawingEntity)
private mapDrawingRepository: Repository<MapDrawingEntity>, private mapDrawingRepository: Repository<MapDrawingEntity>,
@InjectRepository(MapDrawingHistoryEntity)
private mapDrawHistoryRepository: Repository<MapDrawingHistoryEntity>,
private notificationGateway: NotificationGateway, private notificationGateway: NotificationGateway,
) {} ) {}
...@@ -23,8 +28,14 @@ export class DrawService { ...@@ -23,8 +28,14 @@ export class DrawService {
// create new instance if id is null // create new instance if id is null
if (data.mapDrawingId == null || data.mapDrawingId == '') { if (data.mapDrawingId == null || data.mapDrawingId == '') {
drawing.faction = gameperson.faction; drawing.faction = gameperson.faction;
console.log(drawing);
const mapDrawing = await this.mapDrawingRepository.insert(drawing); const mapDrawing = await this.mapDrawingRepository.insert(drawing);
// create a history entity and insert it
const history = await this.mapDrawHistoryRepository.create({
data: data.data,
drawingIsActive: data.drawingIsActive,
mapdrawing: mapDrawing.identifiers[0]['mapDrawingId'],
});
await this.mapDrawHistoryRepository.insert(history);
return mapDrawing.identifiers; return mapDrawing.identifiers;
} }
// get ref from db // get ref from db
...@@ -34,6 +45,12 @@ export class DrawService { ...@@ -34,6 +45,12 @@ export class DrawService {
}); });
if (await draw.ownershipCheck(gameperson.faction, gameperson.role)) { if (await draw.ownershipCheck(gameperson.faction, gameperson.role)) {
// else update the existing instance // else update the existing instance
const history = await this.mapDrawHistoryRepository.create({
data: data.data,
drawingIsActive: data.drawingIsActive,
mapdrawing: data.mapDrawingId,
});
await this.mapDrawHistoryRepository.insert(history);
return await this.mapDrawingRepository.save(drawing); return await this.mapDrawingRepository.save(drawing);
} }
......
import { IsUUID, IsOptional, IsBoolean, Allow } from 'class-validator'; import { IsUUID, IsOptional, IsBoolean, Allow } from 'class-validator';
import { FactionEntity } from '../faction/faction.entity';
import { GameEntity } from '../game/game.entity'; import { GameEntity } from '../game/game.entity';
export class MapDrawingDTO { export class MapDrawingDTO {
...@@ -14,5 +13,4 @@ export class MapDrawingDTO { ...@@ -14,5 +13,4 @@ export class MapDrawingDTO {
gameId: GameEntity; gameId: GameEntity;
@IsBoolean() @IsBoolean()
drawingIsActive?: boolean; drawingIsActive?: boolean;
drawingValidTill?: string;
} }
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