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 { export class MapMarkerDTO {
@IsString() @IsString()
...@@ -7,5 +8,6 @@ export class MapMarkerDTO { ...@@ -7,5 +8,6 @@ export class MapMarkerDTO {
latitude: string; latitude: string;
@IsString() @IsString()
longitude: string; longitude: string;
@IsString()
timestamp: string;
} }
\ No newline at end of file
import { Entity, Column, PrimaryGeneratedColumn, BeforeInsert, PrimaryColumn } from 'typeorm'; import { Entity, Column, PrimaryGeneratedColumn, Timestamp } from 'typeorm';
import * as jwt from 'jsonwebtoken';
import { identifier } from '@babel/types';
@Entity('MapMarker') @Entity('MapMarker')
export class MapMarkerEntity { export class MapMarkerEntity {
@PrimaryGeneratedColumn('uuid') id: string; @PrimaryGeneratedColumn('uuid') id: string;
@Column({type: 'text'}) latitude: string; @Column({type: 'text'}) latitude: string;
@Column({type: 'text'}) longitude: string; @Column({type: 'text'}) longitude: string;
@Column({type: 'timestamp'}) timestamp: Timestamp;
} }
\ No newline at end of file
...@@ -11,19 +11,22 @@ export class MapMarkerService { ...@@ -11,19 +11,22 @@ export class MapMarkerService {
// insert markers // insert markers
async insertLocation(data: MapMarkerDTO){ async insertLocation(data: MapMarkerDTO){
try{
// check for token return if not set return null or something data.timestamp = new Date(Date.now()).toLocaleString(); //get functions runtime as timestamp
const { latitude, longitude } = data; let location = await this.mapmarkerRepository.create(data);
let location = await this.mapmarkerRepository.create(data); await this.mapmarkerRepository.insert(location);
await this.mapmarkerRepository.save(location); }catch(error){
return error;
}
} }
// get all markers // get all markers
async getAllMarkers(): Promise<MapMarkerEntity[]>{ 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 { MapMarkerService } from './mapmarker.service';
import { MapMarkerDTO } from './mapmarker.dto'; import { MapMarkerDTO } from './mapmarker.dto';
...@@ -6,25 +6,21 @@ import { MapMarkerDTO } from './mapmarker.dto'; ...@@ -6,25 +6,21 @@ import { MapMarkerDTO } from './mapmarker.dto';
@Controller('mapmarkers') @Controller('mapmarkers')
export class MapMarkersController { export class MapMarkersController {
constructor(private mapmarkerservice: MapMarkerService){} 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 // Insert figure location
@Put('insertLocation') @Put('insertLocation')
async insertLocation(@Body() data: MapMarkerDTO){ async insertLocation(@Body() data: MapMarkerDTO): Promise<string>{
this.mapmarkerservice.insertLocation(data); try {
return this.mapmarkerservice.insertLocation(data);
} catch (error) {
return error;
}
} }
@Get('getall') @Get('getall')
async getAll(){ async getAll(){
// tarkistaa oikeudet
// hakee kaikki // hakee kaikki
// palauttaa vain halutut
return this.mapmarkerservice.getAllMarkers(); 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