fix: if db is empty, will never show new convos until refresh

This commit is contained in:
Daniel Avila 2023-03-14 18:53:46 -04:00
parent a8344ec5bf
commit 626a8fbd8e

View file

@ -93,7 +93,7 @@ module.exports = {
// getConvos: async () => await Conversation.find({}).sort({ createdAt: -1 }).exec(),
getConvosByPage: async (pageNumber = 1, pageSize = 12) => {
try {
const totalConvos = await Conversation.countDocuments();
const totalConvos = (await Conversation.countDocuments()) || 1;
const totalPages = Math.ceil(totalConvos / pageSize);
const convos = await Conversation.find()
.sort({ createdAt: -1, created: -1 })