1.0.3 • Published 3 years ago

msrv-shared-modules v1.0.3

Weekly downloads
6
License
MIT
Repository
github
Last release
3 years ago

msrv-shared-modules

Installation

npm i msrv-shared-modules

In Node.js

const helpers = require('msrv-shared-modules/modules');

/*ADDS PAGINATION TO YOUR RESPONSE*/

async function get (req,res) {
    try{
        
        const { offset, limit } = helpers.getPaginationValues(req.query);
        const getRecords = await records.find().skip(offset).limit(limit);
        const getRecordsCount = await records.find().countDocuments();  
        const paginatedResponse = helpers.addPagination(req, getRecordsCount , getRecords);
        res.send(paginatedResponse);
    }catch(error){
        console.log(error)
    }
}

/*RESPONSE*/

{
    pagination : {
        offset : 0,
        limit : 20,
        count : 100
    },
    data : { 20 records from 0 to 20},
    links : [
        prev : null,
        current : http://localhost:3000?offset=0&limit=20
        next : http://localhost:3000?offset=20&limit=20
    ]
}
1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago