diff --git a/src/mapmarkers/mapmarker.dto.ts b/src/mapmarkers/mapmarker.dto.ts index 2ce73f2f8df9955aaf9f56042277789eae5f59b3..eab9dc6c55d4a1aeada99bf82b37f1ce2cb10ca1 100644 --- a/src/mapmarkers/mapmarker.dto.ts +++ b/src/mapmarkers/mapmarker.dto.ts @@ -1,4 +1,5 @@ -import { IsString } from 'class-validator'; +import { IsString, IsDateString } from 'class-validator'; +import { Timestamp } from 'typeorm'; export class MapMarkerDTO { @IsString() @@ -7,5 +8,6 @@ export class MapMarkerDTO { latitude: string; @IsString() longitude: string; - + @IsString() + timestamp: string; } \ No newline at end of file diff --git a/src/mapmarkers/mapmarker.entity.ts b/src/mapmarkers/mapmarker.entity.ts index 1314e95cb31357e1c7ab872c5a1cc0ed1597ce41..0134f91ef18aff40ab657f1720fef48fba4829e9 100644 --- a/src/mapmarkers/mapmarker.entity.ts +++ b/src/mapmarkers/mapmarker.entity.ts @@ -1,13 +1,9 @@ -import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, PrimaryColumn } from 'typeorm'; - -import * as jwt from 'jsonwebtoken'; -import { identifier } from '@babel/types'; +import { Entity, Column, PrimaryGeneratedColumn, Timestamp } from 'typeorm'; @Entity('MapMarker') export class MapMarkerEntity { @PrimaryGeneratedColumn('uuid') id: string; - @Column({type: 'text'}) latitude: string; @Column({type: 'text'}) longitude: string; - + @Column({type: 'timestamp'}) timestamp: Timestamp; } \ No newline at end of file diff --git a/src/mapmarkers/mapmarker.service.ts b/src/mapmarkers/mapmarker.service.ts index c95748fed0d8a5d1d59b11e91564f85732f629c3..9c45c0861646eca5de067d45afd64c760215743d 100644 --- a/src/mapmarkers/mapmarker.service.ts +++ b/src/mapmarkers/mapmarker.service.ts @@ -11,19 +11,22 @@ export class MapMarkerService { // insert markers async insertLocation(data: MapMarkerDTO){ - - // check for token return if not set return null or something - const { latitude, longitude } = data; - let location = await this.mapmarkerRepository.create(data); - await this.mapmarkerRepository.save(location); + try{ + data.timestamp = new Date(Date.now()).toLocaleString(); //get functions runtime as timestamp + let location = await this.mapmarkerRepository.create(data); + await this.mapmarkerRepository.insert(location); + }catch(error){ + return error; + } } // get all markers async getAllMarkers(): Promise<MapMarkerEntity[]>{ + try{ + return this.mapmarkerRepository.find(); + }catch(error){ + return error.message; + } - // const users= this.mapmarkerRepository.find(); - // users.map - // user. - return this.mapmarkerRepository.find(); } } \ No newline at end of file diff --git a/src/mapmarkers/mapmarkers.controller.ts b/src/mapmarkers/mapmarkers.controller.ts index 793f3cb61481cd5bec84b5ed18ed664f7564f2cd..f07570fa909300fff101bdf5213d158c14fba181 100644 --- a/src/mapmarkers/mapmarkers.controller.ts +++ b/src/mapmarkers/mapmarkers.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Post, Body, UsePipes, ValidationPipe, Get, Put, UseGuards, Req } from '@nestjs/common'; +import { Controller, Body, Get, Put } from '@nestjs/common'; import { MapMarkerService } from './mapmarker.service'; import { MapMarkerDTO } from './mapmarker.dto'; @@ -6,25 +6,21 @@ import { MapMarkerDTO } from './mapmarker.dto'; @Controller('mapmarkers') export class MapMarkersController { constructor(private mapmarkerservice: MapMarkerService){} - - // update user location - @Post('location') - async getLoctaion(@Body() data: MapMarkerDTO){ - // get user location && id - // update location to database - return this.mapmarkerservice.insertLocation(data); - } // Insert figure location @Put('insertLocation') - async insertLocation(@Body() data: MapMarkerDTO){ - this.mapmarkerservice.insertLocation(data); + async insertLocation(@Body() data: MapMarkerDTO): Promise<string>{ + try { + return this.mapmarkerservice.insertLocation(data); + } catch (error) { + return error; + } } @Get('getall') async getAll(){ + // tarkistaa oikeudet // hakee kaikki - // palauttaa vain halutut return this.mapmarkerservice.getAllMarkers(); } }