balena-cli/lib/resin/models/device.coffee

50 lines
1.1 KiB
CoffeeScript
Raw Normal View History

2014-11-19 17:38:15 +00:00
canvas = require('./_canvas')
2014-11-26 14:32:57 +00:00
_ = require('lodash')
2014-11-26 16:38:02 +00:00
errors = require('../errors/errors')
2014-11-26 18:02:59 +00:00
server = require('../server/server')
settings = require('../settings')
2014-11-19 17:38:15 +00:00
2014-11-28 16:46:24 +00:00
exports.getAll = (callback) ->
return canvas.get
resource: 'device'
options:
expand: 'application'
orderby: 'name asc'
.then (devices) ->
if _.isEmpty(devices)
return callback(new errors.NotAny('devices'))
return callback(null, devices)
.catch (error) ->
return callback(error)
exports.getAllByApplication = (applicationId, callback) ->
2014-11-19 17:38:15 +00:00
return canvas.get
resource: 'device'
options:
filter:
application: applicationId
expand: 'application'
orderby: 'name asc'
2014-11-26 14:32:57 +00:00
.then (devices) ->
if _.isEmpty(devices)
2014-11-26 18:02:59 +00:00
return callback(new errors.NotAny('devices'))
2014-11-26 14:32:57 +00:00
2014-11-26 18:02:59 +00:00
return callback(null, devices)
2014-11-21 17:23:29 +00:00
2014-11-26 18:02:59 +00:00
.catch (error) ->
return callback(error)
exports.remove = (id, callback) ->
2014-11-21 17:23:29 +00:00
return canvas.delete
resource: 'device'
id: id
2014-11-26 18:02:59 +00:00
.then ->
return callback()
.catch (error) ->
return callback(error)
exports.identify = (uuid, callback) ->
2014-12-05 14:53:59 +00:00
server.post(settings.get('urls.identify'), { uuid }, callback)