Merge pull request #144 from resin-io/jviotti/refactor/note

Refactor note set command to use promises
This commit is contained in:
Juan Cruz Viotti 2015-08-17 08:01:47 -04:00
commit ee286c5690
2 changed files with 15 additions and 9 deletions

View File

@ -1,5 +1,7 @@
(function() {
var _, resin;
var Promise, _, resin;
Promise = require('bluebird');
_ = require('lodash');
@ -20,10 +22,12 @@
],
permission: 'user',
action: function(params, options, done) {
if (_.isEmpty(params.note)) {
return done(new Error('Missing note content'));
}
return resin.models.device.note(options.device, params.note).nodeify(done);
return Promise["try"](function() {
if (_.isEmpty(params.note)) {
throw new Error('Missing note content');
}
return resin.models.device.note(options.device, params.note);
}).nodeify(done);
}
};

View File

@ -1,3 +1,4 @@
Promise = require('bluebird')
_ = require('lodash')
resin = require('resin-sdk')
@ -25,8 +26,9 @@ exports.set =
]
permission: 'user'
action: (params, options, done) ->
Promise.try ->
if _.isEmpty(params.note)
throw new Error('Missing note content')
if _.isEmpty(params.note)
return done(new Error('Missing note content'))
resin.models.device.note(options.device, params.note).nodeify(done)
resin.models.device.note(options.device, params.note)
.nodeify(done)