Chat history pages w/ page & limit params.

Updated api to use page and limit for fetching chat history.
This commit is contained in:
2020-12-04 22:29:50 +01:00
parent da8251c733
commit 6503b309c5
2 changed files with 7 additions and 7 deletions

View File

@@ -2,11 +2,11 @@ const path = require("path");
const { history, clearHistory } = require(path.join(__dirname + "/../api/redis")); const { history, clearHistory } = require(path.join(__dirname + "/../api/redis"));
const getAllHistory = (req, res) => { const getAllHistory = (req, res) => {
let { skip, take } = req.query; let { page, limit } = req.query;
skip = !isNaN(skip) ? Number(skip) : undefined; page = !isNaN(page) ? Number(page) : undefined;
take = !isNaN(take) ? Number(take) : undefined; limit = !isNaN(limit) ? Number(limit) : undefined;
return history(skip, take) return history(page, limit)
.then(messages => res.json(messages)) .then(messages => res.json(messages))
.catch(error => res.status(500).json({ .catch(error => res.status(500).json({
message: error.message, message: error.message,

View File

@@ -280,10 +280,10 @@ const register = (username, password) => {
}); });
}; };
const getChatHistory = (skip = null, take = null) => { const getChatHistory = (page=1, limit=10) => {
const url = new URL("/api/chat/history", BASE_URL); const url = new URL("/api/chat/history", BASE_URL);
if (!isNaN(skip)) url.searchParams.append("skip", skip); if (!isNaN(page)) url.searchParams.append("page", page);
if (!isNaN(take)) url.searchParams.append("take", take); if (!isNaN(limit)) url.searchParams.append("limit", limit);
return fetch(url.href).then(resp => resp.json()); return fetch(url.href).then(resp => resp.json());
}; };