find users news by typing their usernames in search box and fix FF CSS issue

This commit is contained in:
Arsen Melikyan
2015-11-01 16:58:28 +04:00
parent f7c8932f8e
commit 8a5e12f6f3
3 changed files with 31 additions and 3 deletions

View File

@@ -62,6 +62,7 @@ module.exports = function(app) {
var findStoryById = observeMethod(Story, 'findById');
var countStories = observeMethod(Story, 'count');
router.post('/news/userstories', userStories);
router.get('/news/hot', hotJSON);
router.get('/stories/hotStories', hotJSON);
router.get(
@@ -104,6 +105,27 @@ module.exports = function(app) {
);
}
function userStories({ body: { search = '' } = {} }, res, next) {
if (!search || typeof search !== 'string') {
return res.sendStatus(404);
}
return app.dataSources.db.connector
.collection('story')
.find({
'author.username': search.replace('$', '')
})
.toArray(function(err, items) {
if (err) {
return next(err);
}
if (items && items.length !== 0) {
return res.json(items.sort(sortByRank));
}
return res.sendStatus(404);
});
}
function hot(req, res) {
return res.render('stories/index', {
title: 'Top Stories on Camper News',