Chathistory only returns funcs and used by router.

This commit is contained in:
2020-11-20 16:29:26 +01:00
parent f1d500936b
commit ee5f817248
2 changed files with 24 additions and 24 deletions

View File

@@ -1,33 +1,29 @@
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) => {
const getAllHistory = (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);
}
});
return history(skip, take)
.then(messages => res.json(messages))
.catch(error => res.status(500).json({
message: error.message,
success: false
}));
};
router.route("/chat/history").delete(async (req, res) => {
try {
const messages = await clearHistory();
res.json(messages)
} catch(error) {
res.status(500).send(error);
}
});
const deleteHistory = (req, res) => {
return clearHistory()
.then(message => res.json(message))
.catch(error => res.status(500).json({
message: error.message,
success: false
}));
};
module.exports = router;
module.exports = {
getAllHistory,
deleteHistory
};

View File

@@ -16,6 +16,7 @@ const virtualRegistrationApi = require(path.join(
__dirname + "/virtualRegistration"
));
const lottery = require(path.join(__dirname + "/lottery"));
const chatHistoryApi = require(path.join(__dirname + "/chatHistory"));
const router = express.Router();
@@ -60,6 +61,9 @@ router.post('/winner/notify/:id', virtualRegistrationApi.sendNotificationToWinne
router.get('/winner/:id', virtualRegistrationApi.getWinesToWinnerById);
router.post('/winner/:id', virtualRegistrationApi.registerWinnerSelection);
router.get('/chat/history', chatHistoryApi.getAllHistory)
router.delete('/chat/history', mustBeAuthenticated, chatHistoryApi.deleteHistory)
router.post('/login', userApi.login);
router.post('/register', mustBeAuthenticated, userApi.register);
router.get('/logout', userApi.logout);