Permalink
Browse files

Added logs per user/app

  • Loading branch information...
Hadrien Jouet
Hadrien Jouet committed Jan 27, 2013
1 parent b054cdb commit 51145635d06fa6b78e4bd739d1c67e2612f65bb7
Showing with 30 additions and 2 deletions.
  1. +24 −0 lib/ishiki.js
  2. +6 −2 models/_base.js
View
@@ -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);
+ });
+ });
});
};
View
@@ -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.