Refactor models (merge Players in Games), add cursor to correspondance games. Finishe...
[vchess.git] / server / models / News.js
index 12f4bf5..2dde566 100644 (file)
@@ -19,7 +19,7 @@ const NewsModel =
           "VALUES " +
         "(" + Date.now() + "," + uid + ",?)";
       db.run(query, content, function(err) {
-        cb(err, {nid: this.lastID});
+        cb(err, { id: this.lastID });
       });
     });
   },
@@ -30,7 +30,8 @@ const NewsModel =
       const query =
         "SELECT * " +
         "FROM News " +
-        "WHERE id > " + cursor + " " +
+        "WHERE added < " + cursor + " " +
+        "ORDER BY added DESC " +
         "LIMIT 10"; //TODO: 10 currently hard-coded
       db.all(query, (err,newsList) => {
         cb(err, newsList);
@@ -38,6 +39,20 @@ const NewsModel =
     });
   },
 
+  getTimestamp: function(cb)
+  {
+    db.serialize(function() {
+      const query =
+        "SELECT added " +
+        "FROM News " +
+        "ORDER BY added DESC " +
+        "LIMIT 1";
+      db.get(query, (err,ts) => {
+        cb(err, ts);
+      });
+    });
+  },
+
   update: function(news)
   {
     db.serialize(function() {