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 getAllHistory = (req, res) => {
let { skip, take } = req.query;
skip = !isNaN(skip) ? Number(skip) : undefined;
take = !isNaN(take) ? Number(take) : undefined;
let { page, limit } = req.query;
page = !isNaN(page) ? Number(page) : undefined;
limit = !isNaN(limit) ? Number(limit) : undefined;
return history(skip, take)
return history(page, limit)
.then(messages => res.json(messages))
.catch(error => res.status(500).json({
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);
if (!isNaN(skip)) url.searchParams.append("skip", skip);
if (!isNaN(take)) url.searchParams.append("take", take);
if (!isNaN(page)) url.searchParams.append("page", page);
if (!isNaN(limit)) url.searchParams.append("limit", limit);
return fetch(url.href).then(resp => resp.json());
};