You can now sort and order the searches.

This commit is contained in:
BurnyLlama 2021-10-03 19:21:47 +02:00
parent 9ebe393f21
commit 30ea4d671e

View File

@ -47,9 +47,12 @@ playerApi.get('/search', async (req, res) => {
})
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)
return res.json({