You can now sort and order the searches.
This commit is contained in:
parent
9ebe393f21
commit
30ea4d671e
|
@ -47,9 +47,12 @@ playerApi.get('/search', async (req, res) => {
|
||||||
})
|
})
|
||||||
|
|
||||||
const name = req.query.name
|
const name = req.query.name
|
||||||
const order = req.query.sortBy === "asc" || req.query.sortBy === "asc" ? req.query.sortBy : "asc"
|
const sort = req.query.sort ?? 'name'
|
||||||
|
const order = req.query.order === "desc" ? -1 : 1
|
||||||
|
const page = req.query.page ?? 1
|
||||||
|
|
||||||
const players = await Player.find({ name: { $regex: name, $options: 'i' }})
|
|
||||||
|
const players = await Player.find({ name: { $regex: name, $options: 'i' }}).sort([[sort, order]]).limit(20).skip((page - 1) * 20)
|
||||||
|
|
||||||
if (!players)
|
if (!players)
|
||||||
return res.json({
|
return res.json({
|
||||||
|
|
Loading…
Reference in New Issue
Block a user