Fix news notification system
[vchess.git] / server / routes / users.js
index 4e51ee1..fc29730 100644 (file)
@@ -41,9 +41,16 @@ router.get("/whoami", access.ajax, (req,res) => {
       email: user.email,
       id: user.id,
       notify: user.notify,
+      newsRead: user.newsRead
     });
   };
-  const anonymous = {name:"", email:"", id:0, notify:false};
+  const anonymous = {
+    name: "",
+    email: "",
+    id: 0,
+    notify: false,
+    newsRead: 0
+  };
   if (!req.cookies.token)
     callback(anonymous);
   else if (req.cookies.token.match(/^[a-z0-9]+$/))
@@ -81,6 +88,12 @@ router.put('/update', access.logged, access.ajax, (req,res) => {
   }
 });
 
+// Special route to update newsRead timestamp:
+router.put('/newsread', access.logged, access.ajax, (req,res) => {
+  UserModel.setNewsRead(req.userId);
+  res.json({});
+});
+
 // Authentication-related methods:
 
 // to: object user (to who we send an email)