Add sort option for posts route /

master
Raymonzut 4 years ago
parent f5b9da4520
commit 74185beb79
No known key found for this signature in database
GPG Key ID: 97CF2D8BE2C69FC7
  1. 9
      server/routes/api/posts.js

@ -16,6 +16,15 @@ async function getPostCollection() {
router.get('/', async (req, res) => {
const posts = await getPostCollection()
if (req.query.sort === '-1' || req.query.sort === '1') {
res.send(
await posts
.find({})
.sort({ date: parseInt(req.query.sort) })
.toArray()
)
return
}
res.send(await posts.find({}).toArray())
})

Loading…
Cancel
Save