add pagination and fix bug
This commit is contained in:
@@ -35,8 +35,26 @@ module.exports.gpsRequest = [
|
||||
|
||||
module.exports.getAllRequest = [
|
||||
async (req, res) => {
|
||||
const data = await RequestGPS.find({}).sort({ status: 1 }).populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic')
|
||||
res.status(200).json(data)
|
||||
let page;
|
||||
let rows;
|
||||
if (!req.query?.rows) {
|
||||
rows = 10
|
||||
} else {
|
||||
rows = req.query.rows
|
||||
}
|
||||
if (!req.query?.page) {
|
||||
page = 0
|
||||
// eslint-disable-next-line eqeqeq
|
||||
} else if (!req.query.page == 1) {
|
||||
page = 0
|
||||
} else {
|
||||
page = req.query.page
|
||||
page = page * rows - rows
|
||||
}
|
||||
const data = await RequestGPS.find({}).sort({ status: 1 }).skip(page).limit(rows)
|
||||
.populate('userId', 'shopName shopNumber shopAddress birthDate score first_name last_name profilePic')
|
||||
const total = Math.ceil((await RequestGPS.estimatedDocumentCount()))
|
||||
res.status(200).json({ data, total })
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user