Skip to content

Commit

Permalink
System API
Browse files Browse the repository at this point in the history
* Client App Versions
* Global Messages
  • Loading branch information
aneesh-neelam committed Feb 22, 2015
1 parent 08d78e4 commit 3ba555c
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
33 changes: 22 additions & 11 deletions api/system.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

var async = require('async');
var path = require('path');

var log;
Expand All @@ -30,13 +31,22 @@ var status = require(path.join(__dirname, 'status'));


exports.get = function (app, data, callback) {
var collection = app.db.collection('system');
var keys = {
android: 1,
ios: 1,
messages: 1
var clientCollection = app.db.collection('client');
var messageCollection = app.db.collection('message');
var parallelTasks = {
client: function (asyncCallback) {
var keys = {
android: 1,
ios: 1,
windows: 1
};
clientCollection.findOne({}, keys, asyncCallback);
},
message: function (asyncCallback) {
messageCollection.find({}, {limit: 10, sort: ['_id', ['desc']}).toArray(asyncCallback);
}
};
var onFetch = function (err, doc) {
var onFetch = function (err, results) {
if (err) {
data.status = status.codes.mongoDown;
if (log) {
Expand All @@ -45,10 +55,11 @@ exports.get = function (app, data, callback) {
console.log(data.status);
callback(true, data);
}
else if (doc) {
data.android = doc.android;
data.ios = doc.ios;
data.messages = doc.messages;
else if (results.client && results.messages) {
data.android = results.client.android;
data.ios = results.client.ios;
data.windows = results.client.windows;
data.messages = results.messages;
data.status = status.codes.success;
callback(false, data);
}
Expand All @@ -61,5 +72,5 @@ exports.get = function (app, data, callback) {
callback(true, data);
}
};
collection.findOne({}, keys, onFetch);
async.parallel(parallelTasks, onFetch);
};
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "VITacademics",
"version": "0.13.38",
"version": "0.13.39",
"description": "VITacademics Backend and Web App",
"bugs": {
"url": "https://github.com/aneesh-neelam/VITacademics/issues",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "VITacademics",
"version": "0.13.38",
"version": "0.13.39",
"description": "VITacademics Backend and Web App",
"homepage": "https://vitacademics-dev.herokuapp.com/",
"bugs": {
Expand Down Expand Up @@ -60,11 +60,11 @@
"moment-timezone": "^0.3.0",
"mongodb": "~1.4.31",
"morgan": "~1.5.1",
"newrelic": "~1.16.2",
"newrelic": "~1.16.4",
"node-ga": "~0.1.1",
"node-logentries": "~0.1.4",
"serve-favicon": "2.2.0",
"underscore": "~1.7.0",
"underscore": "~1.8.1",
"unirest": "~0.4.0"
},
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion routes/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ router.get('/status', function (req, res) {
platform: process.platform,
arch: process.arch,
serverStatus: 'OK',
lastUpdated: '18th February 2015',
lastUpdated: '22nd February 2015',
googleAnalyticsToken: googleAnalyticsToken
};
res.render('status', status);
Expand Down

0 comments on commit 3ba555c

Please sign in to comment.