From 193cedae262fdc675b7e1e281910f949af264e60 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Tue, 28 Apr 2015 09:18:21 -0400 Subject: [PATCH] Check that an application exists before asking it's type. Closes #30 --- build/actions/app.js | 5 +++++ lib/actions/app.coffee | 6 ++++++ package.json | 2 +- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/build/actions/app.js b/build/actions/app.js index 93c0d86a..f32cb875 100644 --- a/build/actions/app.js +++ b/build/actions/app.js @@ -31,6 +31,11 @@ action: function(params, options, done) { return async.waterfall([ function(callback) { + return resin.models.application.has(params.name, callback); + }, function(hasApplication, callback) { + if (hasApplication) { + return callback(new Error('You already have an application with that name!')); + } if (options.type != null) { return callback(null, options.type); } diff --git a/lib/actions/app.coffee b/lib/actions/app.coffee index 636b2d66..47e3baf3 100644 --- a/lib/actions/app.coffee +++ b/lib/actions/app.coffee @@ -37,6 +37,12 @@ exports.create = async.waterfall([ (callback) -> + resin.models.application.has(params.name, callback) + + (hasApplication, callback) -> + if hasApplication + return callback(new Error('You already have an application with that name!')) + return callback(null, options.type) if options.type? resin.models.device.getSupportedDeviceTypes (error, deviceTypes) -> diff --git a/package.json b/package.json index 8501bb34..dba246fc 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,7 @@ "president": "^1.0.0", "progress-stream": "^0.5.0", "resin-cli-visuals": "^0.1.0", - "resin-sdk": "^1.3.1", + "resin-sdk": "^1.3.2", "resin-settings-client": "^1.0.0", "resin-vcs": "^1.2.0", "tmp": "^0.0.25",