mirror of
https://github.com/balena-io/balena-cli.git
synced 2024-12-19 21:57:51 +00:00
48 lines
946 B
CoffeeScript
48 lines
946 B
CoffeeScript
_ = require('lodash')
|
|
Promise = require('bluebird')
|
|
canvas = require('./_canvas')
|
|
errors = require('../errors/errors')
|
|
|
|
exports.getAll = ->
|
|
return canvas.get
|
|
resource: 'application'
|
|
options:
|
|
orderby: 'app_name asc'
|
|
expand: 'device'
|
|
.then (applications) ->
|
|
if _.isEmpty(applications)
|
|
return Promise.reject(new errors.NotAny('applications'))
|
|
|
|
return applications
|
|
|
|
exports.get = (id) ->
|
|
return canvas.get
|
|
resource: 'application'
|
|
id: id
|
|
|
|
.then (application) ->
|
|
if not application?
|
|
return Promise.reject(new errors.NotFound("application #{id}"))
|
|
|
|
return application
|
|
|
|
exports.create = (name, deviceType) ->
|
|
return canvas.post
|
|
resource: 'application'
|
|
data:
|
|
app_name: name
|
|
device_type: deviceType
|
|
|
|
.then (res) ->
|
|
id = res?.id
|
|
|
|
if not id?
|
|
return Promise.reject(new errors.NotFound('created application id'))
|
|
|
|
return id
|
|
|
|
exports.remove = (id) ->
|
|
return canvas.delete
|
|
resource: 'application'
|
|
id: id
|