const mongoose = require("mongoose");
const AdminUser = mongoose.model("Adminuser");

const LogisticpaginatedResults = (AdminUser) => {
	return async (req, res, next) => {
		const page = parseInt(req.query.page) || 1;
		const limit = parseInt(req.query.limit) || 10; // Default limit to 10 if not provided
		const startIndex = (page - 1) * limit;

		const results = {};
		results.results = await AdminUser.find({category:"logisticUser"})
			.sort({ _id: -1 })
			.limit(limit)
			.skip(startIndex)
			.exec();

		res.paginatedResults = results;
		res.totalCount = await AdminUser.countDocuments({ category: "logisticUser" }); // Get total count of documents
		next();
	};
};


module.exports = LogisticpaginatedResults