Chathistory only returns funcs and used by router.
This commit is contained in:
@@ -1,33 +1,29 @@
|
|||||||
const express = require("express");
|
|
||||||
const path = require("path");
|
const path = require("path");
|
||||||
const router = express.Router();
|
|
||||||
|
|
||||||
const { history, clearHistory } = require(path.join(__dirname + "/../api/redis"));
|
const { history, clearHistory } = require(path.join(__dirname + "/../api/redis"));
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
const getAllHistory = (req, res) => {
|
||||||
next();
|
|
||||||
});
|
|
||||||
|
|
||||||
router.route("/chat/history").get(async (req, res) => {
|
|
||||||
let { skip, take } = req.query;
|
let { skip, take } = req.query;
|
||||||
skip = !isNaN(skip) ? Number(skip) : undefined;
|
skip = !isNaN(skip) ? Number(skip) : undefined;
|
||||||
take = !isNaN(take) ? Number(take) : undefined;
|
take = !isNaN(take) ? Number(take) : undefined;
|
||||||
|
|
||||||
try {
|
return history(skip, take)
|
||||||
const messages = await history(skip, take);
|
.then(messages => res.json(messages))
|
||||||
res.json(messages)
|
.catch(error => res.status(500).json({
|
||||||
} catch(error) {
|
message: error.message,
|
||||||
res.status(500).send(error);
|
success: false
|
||||||
}
|
}));
|
||||||
});
|
};
|
||||||
|
|
||||||
router.route("/chat/history").delete(async (req, res) => {
|
const deleteHistory = (req, res) => {
|
||||||
try {
|
return clearHistory()
|
||||||
const messages = await clearHistory();
|
.then(message => res.json(message))
|
||||||
res.json(messages)
|
.catch(error => res.status(500).json({
|
||||||
} catch(error) {
|
message: error.message,
|
||||||
res.status(500).send(error);
|
success: false
|
||||||
}
|
}));
|
||||||
});
|
};
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = {
|
||||||
|
getAllHistory,
|
||||||
|
deleteHistory
|
||||||
|
};
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ const virtualRegistrationApi = require(path.join(
|
|||||||
__dirname + "/virtualRegistration"
|
__dirname + "/virtualRegistration"
|
||||||
));
|
));
|
||||||
const lottery = require(path.join(__dirname + "/lottery"));
|
const lottery = require(path.join(__dirname + "/lottery"));
|
||||||
|
const chatHistoryApi = require(path.join(__dirname + "/chatHistory"));
|
||||||
|
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
|
|
||||||
@@ -60,6 +61,9 @@ router.post('/winner/notify/:id', virtualRegistrationApi.sendNotificationToWinne
|
|||||||
router.get('/winner/:id', virtualRegistrationApi.getWinesToWinnerById);
|
router.get('/winner/:id', virtualRegistrationApi.getWinesToWinnerById);
|
||||||
router.post('/winner/:id', virtualRegistrationApi.registerWinnerSelection);
|
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('/login', userApi.login);
|
||||||
router.post('/register', mustBeAuthenticated, userApi.register);
|
router.post('/register', mustBeAuthenticated, userApi.register);
|
||||||
router.get('/logout', userApi.logout);
|
router.get('/logout', userApi.logout);
|
||||||
|
|||||||
Reference in New Issue
Block a user