Skip to content

Commit

Permalink
Fix #222 : Do not send websocket notification when device is updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Sep 26, 2017
1 parent 2093984 commit c3947ce
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions api/core/device/device.create.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,21 @@ var Promise = require('bluebird');
*/
function create(param) {

var deviceUpdated = false;

// we test first if the device and it's identifier already exist or not
return gladys.utils.sql(queries.getByIdentifier, [param.device.identifier, param.device.service])
.then(function(devices){

if(devices.length){

deviceUpdated = true;

// if device already exist, we update it
return Device.update({id: devices[0].id}, param.device)
.then((rows) => rows[0]);
} else {

// if not, we create the device
return Device.create(param.device);
}
Expand All @@ -39,8 +43,10 @@ function create(param) {
})
.then((result) => {

// broadcast news to everyone
gladys.socket.emit('newDevice', result);
if(!deviceUpdated) {
// broadcast news to everyone
gladys.socket.emit('newDevice', result);
}

return result;
});
Expand Down

0 comments on commit c3947ce

Please sign in to comment.