Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions Web/api/models/Surveys.js
Original file line number Diff line number Diff line change
@@ -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();
});
}
};

4 changes: 4 additions & 0 deletions Web/config/env/development.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) *
Expand Down
3 changes: 3 additions & 0 deletions Web/config/env/production.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) *
Expand Down