diff --git a/lib/actions/device.coffee b/lib/actions/device.coffee index 88fe4904..fa2f8c75 100644 --- a/lib/actions/device.coffee +++ b/lib/actions/device.coffee @@ -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? diff --git a/lib/resin/models/device.coffee b/lib/resin/models/device.coffee index 79a3eb91..9fb0dbee 100644 --- a/lib/resin/models/device.coffee +++ b/lib/resin/models/device.coffee @@ -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)