diff --git a/Web/api/models/Surveys.js b/Web/api/models/Surveys.js index 638b81d..ced19aa 100644 --- a/Web/api/models/Surveys.js +++ b/Web/api/models/Surveys.js @@ -1,34 +1,38 @@ /** -* Surveys.js -* -* @description :: TODO: You might write a short summary of how this model works and what it represents here. -* @docs :: http://sailsjs.org/#!documentation/models -*/ + * Surveys.js + * + * @description :: TODO: You might write a short summary of how this model works and what it represents here. + * @docs :: http://sailsjs.org/#!documentation/models + */ module.exports = { - connection: 'someMongodbServer', - attributes: { - userId : {type: 'string', required: true }, - name: { type: 'string', required: true }, - description: 'string', - location: 'string', - shortUrl: 'string', - qrCode : 'string', - questions: { collection: 'questions' }, - responses : { collection : 'responses'} - }, - // Lifecycle Callbacks - afterCreate: function (values, cb) { - var bitlyApi = require("node-bitlyapi"); - var bitly = new bitlyApi(); - bitly.setAccessToken("2bf203037bb7b0c89d1eb6768b9646551d25d49f"); - bitly.shortenLink("http://xignal.co/id/" + values.id, function (err, results) { - values.shortUrl = JSON.parse(results).data.url; - values.qrCode = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + values.shortUrl; - Surveys.update({ id: values.id }, { shortUrl: values.shortUrl, qrCode: values.qrCode }) - .exec(function (err, updatedServers) {}); - cb(); + connection: 'someMongodbServer', + attributes: { + userId: {type: 'string', required: true}, + name: {type: 'string', required: true}, + description: 'string', + location: 'string', + shortUrl: 'string', + qrCode: 'string', + questions: {collection: 'questions'}, + responses: {collection: 'responses'} + }, + // Lifecycle Callbacks + afterCreate: function (values, cb) { + var bitlyApi = require("node-bitlyapi"); + var bitly = new bitlyApi(); + bitly.setAccessToken(sails.config.bitly.access_token); + bitly.shortenLink(sails.config.surveys_host + '/id/' + values.id, function (err, results) { + if (err) { + return console.log('Bitly API error: ', err); + } + values.shortUrl = JSON.parse(results).data.url; + values.qrCode = "https://chart.googleapis.com/chart?chs=150x150&cht=qr&chl=" + values.shortUrl; + Surveys.update({id: values.id}, {shortUrl: values.shortUrl, qrCode: values.qrCode}) + .exec(function (err, updatedServers) { }); - } + cb(); + }); + } }; diff --git a/Web/config/env/development.js b/Web/config/env/development.js index 3716916..a44ddfc 100644 --- a/Web/config/env/development.js +++ b/Web/config/env/development.js @@ -12,6 +12,10 @@ module.exports = { + // Host that servers up the audience front end - used in generated QR code and short-link + // The bitly api doesn't seem to work with a local host + surveys_host: 'http://xignal-api.azurewebsites.net' + /*************************************************************************** * Set the default database connection for models in the development * * environment (see config/connections.js and config/models.js ) * diff --git a/Web/config/env/production.js b/Web/config/env/production.js index 60dd602..a8bc1b5 100644 --- a/Web/config/env/production.js +++ b/Web/config/env/production.js @@ -12,6 +12,9 @@ module.exports = { + // Host that servers up the audience front end - used in generated QR code and short-link + surveys_host: 'http://xignal-api.azurewebsites.net' + /*************************************************************************** * Set the default database connection for models in the production * * environment (see config/connections.js and config/models.js ) *