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

35 lines
773 B
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')
config = require('../config')
2014-11-19 17:38:15 +00:00
2014-11-26 18:02:59 +00:00
exports.getAll = (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) ->
server.post(config.urls.identify, { uuid }, callback)