product pagination

This commit is contained in:
Sibunnayak 2024-11-26 16:56:57 +05:30
parent 4972241bf7
commit 1cbdaca757

View File

@ -508,8 +508,8 @@ export const getAllProductAdmin = async (req, res) => {
export const getAllProductUser = async (req, res) => { export const getAllProductUser = async (req, res) => {
try { try {
// Set default values for pagination // Set default values for pagination
const PAGE_SIZE = parseInt(req.query?.show || "10"); // const PAGE_SIZE = parseInt(req.query?.show || "10");
const page = parseInt(req.query?.page || "1") - 1; // const page = parseInt(req.query?.page || "1") - 1;
let filter = {}; let filter = {};
// Filter by category name // Filter by category name
@ -553,8 +553,8 @@ export const getAllProductUser = async (req, res) => {
path: "category addedBy brand", path: "category addedBy brand",
select: "categoryName name brandName", select: "categoryName name brandName",
}) })
.limit(PAGE_SIZE) // .limit(PAGE_SIZE)
.skip(PAGE_SIZE * page) // .skip(PAGE_SIZE * page)
.sort({ createdAt: -1 }) .sort({ createdAt: -1 })
.exec(); .exec();