Skip to content

Commit 5114563

Browse files
author
Hadrien Jouet
committed
Added logs per user/app
1 parent b054cdb commit 5114563

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/ishiki.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,29 @@ module.exports = function(app, haibu, path, fs, drone, proxy) {
272272
});
273273
});
274274
});
275+
276+
//return logs for given user/app
277+
this.get('/:userid/:appid/logs', function(userid, appid) {
278+
var res = this.res,
279+
filter = {},
280+
options = {limit: 10, sort: {$natural: -1}};
281+
282+
options.user = userid;
283+
options.app = appid;
284+
285+
if (this.req.body) {
286+
if (this.req.body.type)
287+
filter.type = this.req.body.type;
288+
if (this.req.body.limit)
289+
options.limit = this.req.body.limit.toInt();
290+
}
291+
292+
logModel.get(filter, options, function(err, results) {
293+
if (err)
294+
return haibu.sendResponse(res, 500, err);
295+
296+
haibu.sendResponse(res, 200, results);
297+
});
298+
});
275299
});
276300
};

models/_base.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ var BaseModel = exports.BaseModel = function(options) {
77
};
88

99
//retrieve one entry if id passed, or several if {} passed
10-
BaseModel.prototype.get = function(filter, callback) {
10+
BaseModel.prototype.get = function(filter, options, callback) {
11+
if (!callback) {
12+
callback = options;
13+
options = {};
14+
}
1115
if (!callback) {
1216
callback = filter;
1317
filter = {};
@@ -27,7 +31,7 @@ BaseModel.prototype.get = function(filter, callback) {
2731
});
2832
}
2933
else if (typeof filter == 'object') {
30-
collection.find(filter).toArray(function(err, data) {
34+
collection.find(filter, {}, options).toArray(function(err, data) {
3135
if (err)
3236
callback(err);
3337
else

0 commit comments

Comments
 (0)