From 79a8f4c6a804ac020a3e34ee8167dc8fb25334f5 Mon Sep 17 00:00:00 2001 From: andreagerino Date: Fri, 18 Dec 2015 18:38:18 +0100 Subject: [PATCH] Added finer timestamp management --- routes/storage.js | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/routes/storage.js b/routes/storage.js index 32b8865..ec2c821 100644 --- a/routes/storage.js +++ b/routes/storage.js @@ -8,7 +8,7 @@ var ObjectID = require('mongodb').ObjectID; var assert = assert = require('assert'); // Connection URL -var mongoUrl = 'mongodb://icarus:icarus@localhost:27017/icarus'; +var mongoUrl = 'mongodb://icarus:icarus@webdev.ewlab.di.unimi.it:27017/icarus'; //Connect to the server and intialise the pool var icarusDb; @@ -58,6 +58,14 @@ router.post('/', function(req, res, next){ if(Object.keys(resource).length>0) { + var timestampContainer = getTimestampContainer(resource); + + if(timestampContainer!=undefined){ + + preprocessTimestampContainer(timestampContainer); + + } + collection.insertOne(resource, function (err, r) { if (err != null) { @@ -86,4 +94,34 @@ router.post('/', function(req, res, next){ }); +function getTimestampContainer(arg){ + + if(arg['timestamp']!=undefined&&(arg['timestamp']['utc']!=undefined)||arg['timestamp']['user']!=undefined) + return arg['timestamp']; + + return undefined; + +} + +function preprocessTimestampContainer(container){ + + var utcSeconds = container['utc']; + var userSeconds = container['user']; + + if(utcSeconds!=undefined){ + + var utcMsec = utcSeconds * 1000; + container['utc'] = new Date(utcMsec); + + } + + if(userSeconds!=undefined){ + + var userMsec = userSeconds * 1000; + container['user'] = new Date(userMsec); + + } + +} + module.exports = router; -- 2.18.1