UNPKG

ocpp-js

Version:

Open Charge Point Protocol Implementation in JS

57 lines (50 loc) 1.56 kB
const Promise = require('promise'); const DB = require('../db/index.js'); var Storage = new DB(process.env.storage); module.exports = { handle: function(data){ return new Promise(function(resolve, reject) { // notification is not read yet data.unread = true; /* Storage.findAll('notification', function(err, notifications){ var statusNotifications = notifications.filter(function(item){ return item.type === 'StatusNotification'; }); // TODO: order by timestamp var statusNotif = statusNotifications[0]; // TODO: Check status if (statusNotif.status != data.status) { if ((statusNotif.connectorId === data.connectorId)) { // Status has changed, store notification ! }else{ // Store notification } }else{ if ((statusNotif.connectorId === data.connectorId)) { // Status has changed, store notification ! }else{ // same status, nothing to do } } }); */ var notification = { text: 'Status Notification Update', unread: true, type: 'StatusNotification', timestamp: moment().format(), data: data } Storage.save('notification', notification, function(err){ if(err){ reject(err); }else{ resolve({ StatusNotificationResponse: {} }); } }); }); } }