news sorting by date

This commit is contained in:
tmshv committed 2015-03-07 18:54:05 +03:00
1 parent 36febf0e3b
commit 435c8aef7f
1 file changed
+13 -1
+13 -1
View File
@@ -22,7 +22,10 @@ module.exports = function (app) {
var query = {}; var query = {};
if(this.query.type) query.type = this.query.type; 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);
});
} }
}))); })));
@@ -39,3 +42,12 @@ module.exports = function (app) {
} }
}))); })));
}; };
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;
}