Skip to content
Snippets Groups Projects
Commit 8d5b323c authored by Samuli Virtapohja's avatar Samuli Virtapohja
Browse files

Merge branch 'draw-update' into HEAD

parents aab14ff3 62398b23
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 { FactionEntity } from '../faction/faction.entity';
......@@ -7,8 +13,6 @@ import { FactionEntity } from '../faction/faction.entity';
export class MapDrawingEntity {
@PrimaryGeneratedColumn('uuid') mapDrawingId: string;
@Column({ type: 'bool', nullable: true }) drawingIsActive: boolean;
@Column({ type: 'time', nullable: true }) drawingValidTill: string;
@Column({ type: 'json', nullable: true }) data: JSON;
@ManyToOne(type => FactionEntity, faction => faction.mapDrawings, {
......@@ -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';
import { DrawController } from './draw.controller';
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 { Game_PersonEntity } from '../game/game.entity';
import { NotificationModule } from 'src/notifications/notifications.module';
......@@ -15,6 +18,7 @@ Draw
imports: [
TypeOrmModule.forFeature([
MapDrawingEntity,
MapDrawingHistoryEntity,
FactionEntity,
Game_PersonEntity,
]),
......
......@@ -2,15 +2,20 @@ import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { MapDrawingEntity } from '../draw/coordinate.entity';
import {
MapDrawingEntity,
MapDrawingHistoryEntity,
} from '../draw/coordinate.entity';
import { MapDrawingDTO } from './mapdrawing.dto';
import { NotificationGateway } from 'src/notifications/notifications.gateway';
import { NotificationGateway } from '../notifications/notifications.gateway';
@Injectable()
export class DrawService {
constructor(
@InjectRepository(MapDrawingEntity)
private mapDrawingRepository: Repository<MapDrawingEntity>,
@InjectRepository(MapDrawingHistoryEntity)
private mapDrawHistoryRepository: Repository<MapDrawingHistoryEntity>,
private notificationGateway: NotificationGateway,
) {}
......@@ -23,8 +28,14 @@ export class DrawService {
// create new instance if id is null
if (data.mapDrawingId == null || data.mapDrawingId == '') {
drawing.faction = gameperson.faction;
console.log(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;
}
// get ref from db
......@@ -34,6 +45,12 @@ export class DrawService {
});
if (await draw.ownershipCheck(gameperson.faction, gameperson.role)) {
// 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);
}
......
import { IsUUID, IsOptional, IsBoolean, Allow } from 'class-validator';
import { FactionEntity } from '../faction/faction.entity';
import { GameEntity } from '../game/game.entity';
export class MapDrawingDTO {
......@@ -14,5 +13,4 @@ export class MapDrawingDTO {
gameId: GameEntity;
@IsBoolean()
drawingIsActive?: boolean;
drawingValidTill?: string;
}
......@@ -8,6 +8,7 @@ import {
Min,
Max,
IsOptional,
IsHexColor,
} from 'class-validator';
import { GameEntity } from '../game/game.entity';
......@@ -23,6 +24,8 @@ export class FactionDTO {
@IsNotEmpty()
@Length(2, 31)
factionName: string;
@IsHexColor()
colour: string;
@IsString()
@IsNotEmpty()
@Length(3, 15)
......
......@@ -21,6 +21,7 @@ export class FactionEntity {
@PrimaryGeneratedColumn('uuid') factionId: string;
@Column('text') factionName: string;
@Column({ type: 'float' }) multiplier: number;
@Column('text') colour: string;
@Exclude()
@Column({ type: 'text' })
......
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