Messages from io gets saved to redis in message list. Endpoint for clearing, should be called when a lottery is ended.

This commit is contained in:
2020-03-17 01:05:26 +01:00
parent c893d7d870
commit cda945ead8
3 changed files with 42 additions and 1 deletions

33
api/chatHistory.js Normal file
View File

@@ -0,0 +1,33 @@
const express = require("express");
const path = require("path");
const router = express.Router();
const { history, clearHistory } = require(path.join(__dirname + "/../api/redis"));
router.use((req, res, next) => {
next();
});
router.route("/chat/history").get(async (req, res) => {
let { skip, take } = req.query;
skip = !isNaN(skip) ? Number(skip) : undefined;
take = !isNaN(take) ? Number(take) : undefined;
try {
const messages = await history(skip, take);
res.json(messages)
} catch(error) {
res.status(500).send(error);
}
});
router.route("/chat/history").delete(async (req, res) => {
try {
const messages = await clearHistory();
res.json(messages)
} catch(error) {
res.status(500).send(error);
}
});
module.exports = router;