Answer the question
In order to leave comments, you need to log in
Why is the function not executed and it is not possible to get data from the database?
Good afternoon! There was a problem with requests.
There is a function on the client side - it works fine:
fetchMeetups({commit, state}, options = {}) {
commit('setItems', {resource: 'meetups', items: []}, {root: true})
const url = applyFilters('api/v1/meetups', options.filter)
debugger
return axios.get(url)
.then(res =>{
const meetups = res.data
commit('setItems', {resource: 'meetups', items: meetups}, {root: true})
return state.items
})
.catch(err => console.log(err))
}
const express = require('express');
const router = express.Router();
const MeetupsCtrl = require('../controllers/meetups');
const AuthCtrl = require('../controllers/auth')
router.get('', MeetupsCtrl.getMeetups);
router.get('/secret', AuthCtrl.onlyAuthUser, MeetupsCtrl.getSecret);
router.get('/:id', MeetupsCtrl.getMeetupById);
// Post Route
router.post('', AuthCtrl.onlyAuthUser, MeetupsCtrl.createMeetup);
router.post('/:id/join', AuthCtrl.onlyAuthUser, MeetupsCtrl.joinMeetup);
router.post('/:id/leave', AuthCtrl.onlyAuthUser, MeetupsCtrl.leaveMeetup);
router.patch('/:id', AuthCtrl.onlyAuthUser, MeetupsCtrl.updateMeetup)
module.exports = router;
exports.getMeetups = function(req, res) {
const {category, location} = req.query;
const findQuery = location ? Meetup.find({ processedLocation: { $regex: '.*' + location + '.*' } })
: Meetup.find({})
findQuery
.populate('category')
.populate('joinedPeople')
.limit(6)
.sort({'createdAt': -1})
.exec((errors, meetups) => {
if (errors) {
return res.status(422).send({errors});
}
if (category) {
meetups = meetups.filter(meetup => {
return meetup.category.name === category
})
}
return res.json(meetups);
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question