Add Knightrelay1. Some fixes. Move odd 'isAttackedBy_multiple_colors' to Checkered...
[vchess.git] / server / models / News.js
index 3f98fd6..c10f71f 100644 (file)
@@ -19,7 +19,7 @@ const NewsModel =
           "VALUES " +
         "(" + Date.now() + "," + uid + ",?)";
       db.run(query, content, function(err) {
-        return cb(err, {nid: this.lastID});
+        cb(err, { id: this.lastID });
       });
     });
   },
@@ -30,32 +30,47 @@ 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) => {
-        return cb(err, newsList);
+      db.all(query, (err, newsList) => {
+        cb(err, newsList);
       });
     });
   },
 
-  update: function(news, cb)
+  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() {
       let query =
         "UPDATE News " +
         "SET content = ? " +
         "WHERE id = " + news.id;
-      db.run(query, news.content, cb);
+      db.run(query, news.content);
     });
   },
 
-  remove: function(id, cb)
+  remove: function(id)
   {
     db.serialize(function() {
       const query =
         "DELETE FROM News " +
         "WHERE id = " + id;
-      db.run(query, cb);
+      db.run(query);
     });
   },
 }