Fix some translations and error messages
[vchess.git] / server / routes / news.js
1 let router = require("express").Router();
2 const access = require("../utils/access");
3 const NewsModel = require("../models/News");
4 const sanitizeHtml = require('sanitize-html');
5 const devs = [1]; //hard-coded list of developers IDs, allowed to post news
6
7 router.post("/news", access.logged, access.ajax, (req,res) => {
8 if (devs.includes(req.userId))
9 {
10 const content = sanitizeHtml(req.body.news.content);
11 NewsModel.create(content, req.userId, (err,ret) => {
12 res.json(err || {id:ret.nid});
13 });
14 }
15 });
16
17 router.get("/news", access.ajax, (req,res) => {
18 const cursor = req.query["cursor"];
19 if (cursor.match(/^[0-9]+$/))
20 {
21 NewsModel.getNext(cursor, (err,newsList) => {
22 res.json(err || {newsList:newsList});
23 });
24 }
25 });
26
27 router.put("/news", access.logged, access.ajax, (req,res) => {
28 let news = req.body.news;
29 if (devs.includes(req.userId) && news.id.toString().match(/^[0-9]+$/))
30 {
31 news.content = sanitizeHtml(news.content);
32 NewsModel.update(news);
33 res.json({});
34 }
35 });
36
37 router.delete("/news", access.logged, access.ajax, (req,res) => {
38 const nid = req.query.id;
39 if (devs.includes(req.userId) && nid.toString().match(/^[0-9]+$/))
40 {
41 NewsModel.remove(nid);
42 res.json({});
43 }
44 });
45
46 module.exports = router;