Chat history pages w/ page & limit params.
Updated api to use page and limit for fetching chat history.
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
@@ -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());
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user