Skip to content

Commit e33fec5

Browse files
committed
using baugarten#157 feature (X-Total-Count header)
1 parent a018736 commit e33fec5

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

lib/handlers.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,23 @@ exports.get = function(req, res, next) {
4141
req.quer.exec(function(err, list) {
4242
if (err) {
4343
exports.respond(res, 500, err);
44+
next();
4445
} else if (req.params.id) {
4546
exports.respondOrErr(res, 404, !list && exports.objectNotFound(), 200, (list && _.isArray(list)) ? list[0] : list);
47+
next();
4648
} else {
4749
exports.respondOrErr(res, 500, err, 200, list);
50+
delete req.quer.options;
51+
req.quer.count(function(err, total) {
52+
if (err) {
53+
exports.respond(res, 500, err);
54+
} else {
55+
res.set('X-Total-Count', total);
56+
exports.respondOrErr(res, 500, err, 200, list);
57+
}
58+
next();
59+
});
4860
}
49-
next();
5061
});
5162
}
5263
};

0 commit comments

Comments
 (0)