Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- router.get('/posts',authenticate, async (req,res) => {
- //const _ispublished = req.query.published;
- const match = {}
- const sort = {}
- if(req.query.published){
- match.published = req.query.published === 'true'
- }
- if(req.query.sortBy && req.query.OrderBy){
- sort[req.query.sortBy] = req.query.OrderBy === 'desc' ? -1 : 1
- }
- try {
- await req.user.populate({
- path:'posts',
- match,
- options:{
- limit: parseInt(req.query.limit),
- skip: parseInt(req.query.skip),
- sort
- }
- }).execPopulate()
- res.send(req.user.posts)
- } catch (error) {
- res.status(500).send()
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement