Skip to content

Commit

Permalink
Merge pull request #44 from e-ucm/json
Browse files Browse the repository at this point in the history
JSON response innstead of TEXT/PLAIN: Added some json answers.
  • Loading branch information
Dan Cristian, Rotaru committed Feb 3, 2016
2 parents 0b1b215 + ffc7e01 commit 8598208
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
20 changes: 20 additions & 0 deletions lib/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,25 @@ module.exports = (function() {
});
});

games.removeGame = function (gameId) {
return games.findById(gameId)
.then(function (game) {
if (!game) {
throw {
message: 'Game does not exist',
status: 400
};
}

return games.removeById(gameId).then(function (result, err) {
if (!err) {
return {
message: 'Success.'
};
}
});
});
};

return games;
})();
8 changes: 7 additions & 1 deletion lib/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,13 @@ module.exports = (function () {
db.collection('sessions' + sesionIdentifier).drop();
db.collection('session_opaque_values_' + sesionIdentifier).drop();

return sessions.removeById(sessionId);
return sessions.removeById(sessionId).then(function (result, err) {
if (!err) {
return {
message: 'Success.'
};
}
});
});
};

Expand Down
6 changes: 4 additions & 2 deletions lib/traces.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ module.exports = (function () {
* @param versionId
* @param gameplayId
* @param data
* @returns true or an array of errors from the consumers that failed while consuming the data.
* @returns { message: 'Success.'} or an array of errors from the consumers that failed while consuming the data.
*/
add: function (playerId, versionId, gameplayId, data) {

Expand All @@ -179,7 +179,9 @@ module.exports = (function () {
}
return Q.all(promises)
.then(function () {
return true;
return {
message: 'Success.'
};
}).fail(function (err) {
return err;
});
Expand Down
4 changes: 3 additions & 1 deletion routes/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ router.post('/start/:trackingCode', function (req, res) {
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* true
* {
* "message": "Success."
* }
*
*/
router.post('/track', function (req, res) {
Expand Down
8 changes: 6 additions & 2 deletions routes/games.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,14 @@ router.post('/:id', restUtils.findAndModify(games));
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* true
* {
* "message": "Success."
* }
*
*/
router.delete('/:id', restUtils.deleteById(games));
router.delete('/:id', function (req, res) {
restUtils.processResponse(games.removeGame(req.params.id), res);
});

/**
* @api {get} /games/:gameId/versions Returns all the versions of a given game.
Expand Down
4 changes: 3 additions & 1 deletion routes/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ router.put('/:sessionId/remove', function (req, res) {
*
* @apiSuccessExample Success-Response:
* HTTP/1.1 200 OK
* true
* {
* "message": "Success."
* }
*/
router.delete('/:sessionId', function (req, res) {
var username = req.headers['x-gleaner-user'];
Expand Down
2 changes: 1 addition & 1 deletion test/tests/collectorTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = function(request, db, config) {
.set('Authorization', authToken)
.send([statement])
.end(function (err, res) {
should.equal(res.body, true);
should(res.body).eql({ message: 'Success.' });
done();
});
});
Expand Down

0 comments on commit 8598208

Please sign in to comment.