From 427feab9b7f12786feb978b814ae04c7ea118a1f Mon Sep 17 00:00:00 2001
From: Samuli Virtapohja <l4721@student.jamk.fi>
Date: Fri, 7 Jun 2019 11:06:44 +0300
Subject: [PATCH] Add comments the code on mapmarker

---
 src/mapmarkers/mapmarker.dto.ts         |  5 +++++
 src/mapmarkers/mapmarker.entity.ts      |  5 +++++
 src/mapmarkers/mapmarker.service.ts     | 10 +++++++++-
 src/mapmarkers/mapmarkers.controller.ts |  2 +-
 4 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/src/mapmarkers/mapmarker.dto.ts b/src/mapmarkers/mapmarker.dto.ts
index d4a7f8c..f9821f4 100644
--- a/src/mapmarkers/mapmarker.dto.ts
+++ b/src/mapmarkers/mapmarker.dto.ts
@@ -1,4 +1,9 @@
 import { IsString, IsJSON } from 'class-validator';
+/*
+DTO: MapMarker
+- represents servers data handling.
+*/
+
 
 export class MapMarkerDTO {
     @IsString()
diff --git a/src/mapmarkers/mapmarker.entity.ts b/src/mapmarkers/mapmarker.entity.ts
index ffee47e..41a955d 100644
--- a/src/mapmarkers/mapmarker.entity.ts
+++ b/src/mapmarkers/mapmarker.entity.ts
@@ -2,6 +2,11 @@ import { Entity, Column, PrimaryGeneratedColumn, Timestamp, ManyToOne } from 'ty
 
 import { PersonEntity } from 'src/user/user.entity'
 
+/*
+Entity: MapMarker 
+- represents data that database contains on mapmarker
+*/
+
 @Entity('MapMarker')
 export class MapMarkerEntity {
     @PrimaryGeneratedColumn('uuid') id: string;
diff --git a/src/mapmarkers/mapmarker.service.ts b/src/mapmarkers/mapmarker.service.ts
index 5235e4b..c47ddf0 100644
--- a/src/mapmarkers/mapmarker.service.ts
+++ b/src/mapmarkers/mapmarker.service.ts
@@ -10,6 +10,7 @@ import { userInfo } from 'os';
 @Injectable()
 export class MapMarkerService {
     constructor(
+        //create references to tables as repositories
         @InjectRepository(MapMarkerEntity) private mapmarkerRepository: Repository<MapMarkerEntity>,
         @InjectRepository(PersonEntity) private personRepository: Repository<PersonEntity>
     ) { }
@@ -17,10 +18,15 @@ export class MapMarkerService {
     // insert markers
     async insertLocation(personId: string, data: MapMarkerDTO) {
         try {
-            data.timestamp = new Date(Date.now()).toLocaleString(); //get functions runtime as timestamp
+            //get functions runtime as timestamp
+            data.timestamp = new Date(Date.now()).toLocaleString(); 
+            //check from database for the user who uploads the data
             const user = await this.personRepository.findOne({ where: { id: personId } })
+            //create&copy entity properties
             const location = await this.mapmarkerRepository.create({ ...data, player: user });
+            // insert created entity NOTE: insert method doesn't check for duplicates.
             await this.mapmarkerRepository.insert(location);
+            // return data and player id&name
             return { ...data, player: location.player.nameObject() };
         } catch (error) {
             return error;
@@ -30,7 +36,9 @@ export class MapMarkerService {
     // get all markers
     async getAllMarkers() {
         try {
+            // find all markers with specified player
             const markers = await this.mapmarkerRepository.find({ relations: ['player'] });
+            // return markers from database with said playerdata
             return markers.map(marker => { return { ...marker, player: marker.player.nameObject() } });
         } catch (error) {
             return error.message;
diff --git a/src/mapmarkers/mapmarkers.controller.ts b/src/mapmarkers/mapmarkers.controller.ts
index f6c2e0b..6aa89c9 100644
--- a/src/mapmarkers/mapmarkers.controller.ts
+++ b/src/mapmarkers/mapmarkers.controller.ts
@@ -20,7 +20,7 @@ export class MapMarkersController {
         }
     }
 
-    // return all markers
+    // return all markers through service
     @Get('getall')
     async getAll(){
         return this.mapmarkerservice.getAllMarkers();
-- 
GitLab