How to configure paging method on Node Express?

0

I have my paging method working perfectly with this URL:

http://localhost:3000/menuspage

See the code below;

exports.list_all_dataProviders = async (req, res) => {


    const { filter, skip, limit, sort, projection } = aqp(req.query);
    Menus
      .find(filter)
      .skip(skip)
      .limit(limit)
      .sort(sort)
      .select(projection)
      .exec(async (err, result) => {

        if (err) {
          return res.status(500).jsonp({message:"There was an internal error listing all the providers " + err});
        }
        let count = await Menus.find().count()
        res.status(200).jsonp({
          limit: limit,
          skip: skip,
          total: count,
          data: result
        });
      });
  };

This is the return in json;

{
    "total": 17,
    "data": [
        {
            "_id": "5b6abfb085dc590dc042063d",
            "id": "donut",
            "name": "Donut",
            "description": "Coberto com chantilly",
            "price": 2.5,
            "restaurantId": "bread-bakery"
        },
        {
            "_id": "5b6abfb085dc590dc042063e",
            "id": "bread",
            "name": "Pão Artesanal Italiano",
            "description": "Pão artesanal com queijos italianos",
            "price": 15.9,
            "restaurantId": "bread-bakery"
        },

>>>> e os restos dos registros.....

    ]
}

What I need is to modify my method so that I can put my URL like this

  

link

And it returns me to the first page with 4 records.

I'm having trouble modifying this method because I got it ready, and lack of experience also contributed.

    
asked by anonymous 16.08.2018 / 15:37

1 answer

1

Oops! You can give a search about this in this link of the expression: link

But it would look something like this:

    app.get('/:menuspage?', function mostraPaginas(req, res) {
  console.log(req.route);
  res.send('GET');
});

{ path: '/menuspage/:page?',
  stack:
   [ { handle: [Function: mostraPaginas],
       name: 'pages',
       params: undefined,
       path: undefined,
       keys: [],
       regexp: /^\/?$/i,
       method: 'get' } ],
  methods: { get: true } }

I hope to have helped!

    
16.08.2018 / 16:08