ensures query supports pagination
This commit is contained in:
@@ -3,7 +3,7 @@ import { render } from 'react-dom';
|
||||
import { BrowserRouter as Router } from 'react-router-dom';
|
||||
import { SearchParamsProvider } from './utilities/SearchParams';
|
||||
import { LocaleProvider } from './utilities/Locale';
|
||||
import StatusList, { StatusListProvider } from './modules/Status';
|
||||
import { StatusListProvider } from './modules/Status';
|
||||
import { UserProvider } from './data/User';
|
||||
import Routes from './Routes';
|
||||
|
||||
|
||||
@@ -2,15 +2,19 @@ const httpStatus = require('http-status');
|
||||
const formatErrorResponse = require('../../responses/formatError');
|
||||
|
||||
const query = (req, res) => {
|
||||
const queryOptions = {};
|
||||
const paginateQuery = {
|
||||
limit: req.query.limit,
|
||||
page: req.query.page,
|
||||
options: {},
|
||||
};
|
||||
|
||||
if (req.query.depth) {
|
||||
queryOptions.autopopulate = {
|
||||
paginateQuery.options.autopopulate = {
|
||||
maxDepth: req.query.depth,
|
||||
};
|
||||
}
|
||||
|
||||
req.model.paginate(req.model.apiQuery(req.query, req.locale), { options: queryOptions }, (err, result) => {
|
||||
req.model.paginate(req.model.apiQuery(req.query, req.locale), paginateQuery, (err, result) => {
|
||||
if (err) {
|
||||
return res.status(httpStatus.INTERNAL_SERVER_ERROR).json(formatErrorResponse(err, 'mongoose'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user