Make environment variables model callback based

This commit is contained in:
Juan Cruz Viotti 2014-11-26 14:11:02 -04:00
parent fa83019945
commit debc017ba3
2 changed files with 15 additions and 10 deletions

View File

@ -13,17 +13,15 @@ exports.list = authHooks.failIfNotLoggedIn (program) ->
if not applicationId?
resin.errors.handle(new Error('You have to specify an application'))
resin.models.environmentVariables.getAll(applicationId).then (environmentVariables) ->
resin.models.environmentVariables.getAll applicationId, (error, environmentVariables) ->
resin.errors.handle(error) if error?
if not program.parent.verbose?
environmentVariables = _.reject(environmentVariables, isSystemVariable)
resin.log.out(resin.ui.widgets.table.horizontal(environmentVariables))
.catch(resin.errors.handle)
exports.remove = authHooks.failIfNotLoggedIn (id, program) ->
resin.ui.patterns.remove 'environment variable', program.parent.yes, (callback) ->
resin.models.environmentVariables.remove(id).then ->
return callback()
.catch(callback)
resin.models.environmentVariables.remove(id, callback)
, resin.errors.handle

View File

@ -1,8 +1,7 @@
Promise = require('bluebird')
canvas = require('./_canvas')
errors = require('../errors/errors')
exports.getAll = (applicationId) ->
exports.getAll = (applicationId, callback) ->
return canvas.get
resource: 'environment_variable'
options:
@ -12,10 +11,18 @@ exports.getAll = (applicationId) ->
.then (environmentVariables) ->
if not environmentVariables?
return Promise.reject(new errors.NotFound('environment variables'))
return environmentVariables
return callback(new errors.NotFound('environment variables'))
exports.remove = (id) ->
return callback(null, environmentVariables)
.catch (error) ->
return callback(error)
exports.remove = (id, callback) ->
return canvas.delete
resource: 'environment_variable'
id: id
.then ->
return callback()
.catch (error) ->
return callback(error)