Skip to content

Commit

Permalink
Added logs per user/app
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadrien Jouet committed Jan 27, 2013
1 parent b054cdb commit 5114563
Showing 2 changed files with 30 additions and 2 deletions.
24 changes: 24 additions & 0 deletions lib/ishiki.js
Original file line number Diff line number Diff line change
@@ -272,5 +272,29 @@ module.exports = function(app, haibu, path, fs, drone, proxy) {
});
});
});

//return logs for given user/app
this.get('/:userid/:appid/logs', function(userid, appid) {
var res = this.res,
filter = {},
options = {limit: 10, sort: {$natural: -1}};

options.user = userid;
options.app = appid;

if (this.req.body) {
if (this.req.body.type)
filter.type = this.req.body.type;
if (this.req.body.limit)
options.limit = this.req.body.limit.toInt();
}

logModel.get(filter, options, function(err, results) {
if (err)
return haibu.sendResponse(res, 500, err);

haibu.sendResponse(res, 200, results);
});
});
});
};
8 changes: 6 additions & 2 deletions models/_base.js
Original file line number Diff line number Diff line change
@@ -7,7 +7,11 @@ var BaseModel = exports.BaseModel = function(options) {
};

//retrieve one entry if id passed, or several if {} passed
BaseModel.prototype.get = function(filter, callback) {
BaseModel.prototype.get = function(filter, options, callback) {
if (!callback) {
callback = options;
options = {};
}
if (!callback) {
callback = filter;
filter = {};
@@ -27,7 +31,7 @@ BaseModel.prototype.get = function(filter, callback) {
});
}
else if (typeof filter == 'object') {
collection.find(filter).toArray(function(err, data) {
collection.find(filter, {}, options).toArray(function(err, data) {
if (err)
callback(err);
else

0 comments on commit 5114563

Please sign in to comment.