'use strict'; module.exports = function(db) { var module = {}; module.deviceIds = ['CENSIS-LoRa-1','CENSIS-LoRa-2','CENSIS-LoRa-3','CENSIS-LoRa-4','HIE-mobile-1','HIE-demo','HIE-mobile-2','HIE-smart-campus-1','HIE-smart-campus-2','HIE-smart-campus-3','HIE-smart-campus-4','HIE-smart-campus-5','HIE-smart-campus-6','HIE-smart-campus-7','HIE-mDot-1']; module.sqlInsertTrack = function(data) { let _data = data; console.log('sqlInsertTrack', _data.locationid, _data.timestamp); return new Promise(function(resolve, reject) { db.func('insert_track', [_data.locationid, _data.timestamp, _data.count, _data.total]) .then(()=> { return resolve('ok'); }) .catch((err)=> { return reject(err); }); }); }; module.addNewTrack = function(data) { console.log('addNewTrack'); var self = this; return new Promise((resolve, reject) => { let _data = {}; _data.timestamp = new Date(); _data.locationid = data.locationid; _data.count = data.count; _data.total = data.total; self.sqlInsertTrack(_data) .then((d)=> { console.log('Postgres returns', d); return resolve({reply: 'track inserted'}); }) .catch((err)=> { return reject(err); }); }); }; return module; };