import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { MapDrawingEntity } from '../draw/coordinate.entity'; @Injectable() export class DrawService { constructor( @InjectRepository(MapDrawingEntity) private mapDrawingRepository: Repository<MapDrawingEntity>, ) {} async draw(gameId, data: MapDrawingEntity) { data['gameId'] = gameId; const drawing = await this.mapDrawingRepository.create(data); if (data.mapDrawingId == null || data.mapDrawingId == '') { // luo uuden instanssin. const mapDrawing = await this.mapDrawingRepository.insert(drawing); return mapDrawing.identifiers; } else { //päivittää mapDrawingin return await this.mapDrawingRepository.save(drawing); } } // draw map based on game and async drawMap(id, data: MapDrawingEntity) { data['gameId'] = id; data['drawingIsActive'] = true; // get faction const mapDrawings = await this.mapDrawingRepository.create(data); // return mapdrawings with given faction and gameid return await this.mapDrawingRepository.find(mapDrawings); } }