diff --git a/routes/news.js b/routes/news.js index 16b3dcb9..7c822f0d 100644 --- a/routes/news.js +++ b/routes/news.js @@ -22,7 +22,10 @@ module.exports = function (app) { var query = {}; if(this.query.type) query.type = this.query.type; - this.body = yield db.c("posts").find(query).skip(skip).limit(count).toArray(); + this.body = yield db.c("posts").find(query).skip(skip).limit(count).toArray() + .then(function(items){ + return items.sort(sortNewsByDate); + }); } }))); @@ -38,4 +41,13 @@ module.exports = function (app) { } } }))); -}; \ No newline at end of file +}; + +function sortNewsByDate(i1, i2) { + var t1 = new Date(i1.date).getTime(); + var t2 = new Date(i2.date).getTime(); + + if (t1 < t2) return 1; + if (t1 > t2) return -1; + return 0; +} \ No newline at end of file