Make device model callback based

This commit is contained in:
Juan Cruz Viotti 2014-11-26 14:02:59 -04:00
parent 213cab0480
commit fa83019945
2 changed files with 21 additions and 12 deletions

View File

@ -2,7 +2,8 @@ resin = require('../resin')
authHooks = require('../hooks/auth')
exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
resin.models.device.getAll(applicationId).then (devices) ->
resin.models.device.getAll applicationId, (error, devices) ->
resin.errors.handle(error) if error?
resin.log.out resin.ui.widgets.table.horizontal devices, (device) ->
device.application = device.application[0].app_name
@ -14,14 +15,11 @@ exports.list = authHooks.failIfNotLoggedIn (applicationId) ->
return device
, [ 'ID', 'Name', 'Device Type', 'Is Online', 'IP Address', 'Application', 'Status', 'Last Seen' ]
.catch(resin.errors.handle)
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
resin.ui.patterns.remove 'device', program.parent.yes, (callback) ->
resin.models.device.remove(id).then ->
return callback()
.catch(callback)
resin.models.device.remove(id, callback)
, resin.errors.handle
exports.identify = authHooks.failIfNotLoggedIn (uuid) ->
resin.server.post(resin.config.urls.identify, { uuid }, resin.errors.handle)
resin.models.device.identify uuid, (error) ->
resin.errors.handle(error) if error?

View File

@ -1,9 +1,10 @@
canvas = require('./_canvas')
_ = require('lodash')
Promise = require('bluebird')
errors = require('../errors/errors')
server = require('../server/server')
config = require('../config')
exports.getAll = (applicationId) ->
exports.getAll = (applicationId, callback) ->
return canvas.get
resource: 'device'
options:
@ -13,11 +14,21 @@ exports.getAll = (applicationId) ->
orderby: 'name asc'
.then (devices) ->
if _.isEmpty(devices)
return Promise.reject(new errors.NotAny('devices'))
return callback(new errors.NotAny('devices'))
return devices
return callback(null, devices)
exports.remove = (id) ->
.catch (error) ->
return callback(error)
exports.remove = (id, callback) ->
return canvas.delete
resource: 'device'
id: id
.then ->
return callback()
.catch (error) ->
return callback(error)
exports.identify = (uuid, callback) ->
server.post(config.urls.identify, { uuid }, callback)