news sorting by date
This commit is contained in:
1 parent
36febf0e3b
commit
435c8aef7f
1 file changed
+14
-2
+14
-2
@@ -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) {
|
||||
}
|
||||
}
|
||||
})));
|
||||
};
|
||||
};
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user