Adds pagination to customerService

This commit is contained in:
olivermrbl
2020-09-03 12:32:28 +02:00
parent 564b30ebbc
commit bcd54d7412
2 changed files with 17 additions and 4 deletions

View File

@@ -9,9 +9,14 @@ export default async (req, res) => {
"last_name",
])
const customers = await customerService.list(query)
const limit = parseInt(req.query.limit) || 0
const offset = parseInt(req.query.offset) || 0
res.json({ customers })
const customers = await customerService.list(query, offset, limit)
const numCustomers = await customerService.count()
res.json({ customers, total_count: numCustomers })
} catch (error) {
throw error
}

View File

@@ -113,8 +113,16 @@ class CustomerService extends BaseService {
* @param {Object} selector - the query object for find
* @return {Promise} the result of the find operation
*/
list(selector) {
return this.customerModel_.find(selector)
list(selector, offset, limit) {
return this.customerModel_.find(selector, {}, offset, limit)
}
/**
* Return the total number of documents in database
* @return {Promise} the result of the count operation
*/
count() {
return this.customerModel_.count()
}
/**