2014-11-26 10:32:57 -04:00
|
|
|
_ = require('lodash')
|
2014-11-18 10:11:18 -04:00
|
|
|
canvas = require('./_canvas')
|
2014-11-26 12:38:02 -04:00
|
|
|
errors = require('../errors/errors')
|
2014-11-26 13:54:05 -04:00
|
|
|
server = require('../server/server')
|
2014-12-03 12:03:54 -04:00
|
|
|
settings = require('../settings')
|
2014-11-18 10:11:18 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
exports.getAll = (callback) ->
|
2014-11-18 10:11:18 -04:00
|
|
|
return canvas.get
|
|
|
|
resource: 'application'
|
|
|
|
options:
|
|
|
|
orderby: 'app_name asc'
|
|
|
|
expand: 'device'
|
2014-11-26 10:32:57 -04:00
|
|
|
.then (applications) ->
|
|
|
|
if _.isEmpty(applications)
|
2014-11-26 13:54:05 -04:00
|
|
|
return callback(new errors.NotAny('applications'))
|
2014-11-26 10:32:57 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
return callback(null, applications)
|
2014-11-19 09:23:40 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
.catch (error) ->
|
|
|
|
return callback(error)
|
|
|
|
|
|
|
|
exports.get = (id, callback) ->
|
2014-11-19 09:23:40 -04:00
|
|
|
return canvas.get
|
|
|
|
resource: 'application'
|
|
|
|
id: id
|
|
|
|
|
|
|
|
.then (application) ->
|
|
|
|
if not application?
|
2014-11-26 13:54:05 -04:00
|
|
|
return callback(new errors.NotFound("application #{id}"))
|
|
|
|
|
|
|
|
return callback(null, application)
|
2014-11-19 09:23:40 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
.catch (error) ->
|
|
|
|
return callback(error)
|
2014-11-21 09:43:03 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
exports.create = (name, deviceType, callback) ->
|
2014-11-24 10:45:54 -04:00
|
|
|
return canvas.post
|
|
|
|
resource: 'application'
|
|
|
|
data:
|
|
|
|
app_name: name
|
|
|
|
device_type: deviceType
|
|
|
|
|
|
|
|
.then (res) ->
|
|
|
|
id = res?.id
|
|
|
|
|
|
|
|
if not id?
|
2014-11-26 13:54:05 -04:00
|
|
|
return callback(new errors.NotFound('created application id'))
|
|
|
|
|
|
|
|
return callback(null, id)
|
2014-11-24 10:45:54 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
.catch (error) ->
|
|
|
|
return callback(error)
|
2014-11-24 10:45:54 -04:00
|
|
|
|
2014-11-26 13:54:05 -04:00
|
|
|
exports.remove = (id, callback) ->
|
2014-11-21 09:43:03 -04:00
|
|
|
return canvas.delete
|
|
|
|
resource: 'application'
|
|
|
|
id: id
|
2014-11-26 13:54:05 -04:00
|
|
|
.then ->
|
|
|
|
return callback()
|
|
|
|
.catch (error) ->
|
|
|
|
return callback(error)
|
|
|
|
|
|
|
|
exports.restart = (id, callback) ->
|
2014-12-05 10:53:59 -04:00
|
|
|
url = _.template(settings.get('urls.applicationRestart'), { id })
|
2014-12-01 10:06:03 -04:00
|
|
|
server.post(url, callback)
|