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

timestamps added

parent 10bf5295
No related branches found
No related tags found
1 merge request!2Geo json
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
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
......@@ -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
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();
}
}
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