1exports.generateList = function (req, res) {
2 subcategories
3 .find({})//grabs all subcategoris
4 .where('categoryId').ne([])//filter out the ones that don't have a category
5 .populate('categoryId')
6 .where('active').equals(true)
7 .where('display').equals(true)
8 .where('categoryId.active').equals(true)
9 .where('display').in('categoryId').equals(true)
10 .exec(function (err, data) {
11 if (err) {
12 console.log(err);
13 console.log('error returned');
14 res.send(500, { error: 'Failed insert' });
15 }
16
17 if (!data) {
18 res.send(403, { error: 'Authentication Failed' });
19 }
20
21 res.send(200, data);
22 console.log('success generate List');
23 });
24 };
1router.post('/travellers',
2 passport.authenticate('jwt', { "session": false }), function(req, res, next) {
3 var pickup_location = req.body.pickup_location;
4 var delivery_location = req.body.delivery_location;
5 var date = req.body.date;
6 var sender = req.user._id;
7 var locals = {
8 travellers: [],
9 senders: []
10 };
11
12 async.series([
13 // Load travels first
14 function(callback) {
15 Travel.find({ "date": date }, function (err, travels) {
16 if (err) return callback(err);
17 locals.travels = travels;
18 callback();
19 });
20 },
21 // Load users (won't be called before task 1's "task callback" has been called)
22 function(callback) {
23 async.forEach(locals.travels, function (travel, callback) {
24 User.findById(travel.traveller, function (err, user) {
25 if (err) return callback(err);
26 data = {
27 "name": user.name,
28 "email": user.email,
29 "phone": user.phone,
30 "image_url": user.image_url,
31 "type": "traveller"
32 };
33 console.log(data);
34 local.travellers.push(data);
35 callback();
36 });
37 }, function (err) {
38 if (err) return callback(err);
39 callback();
40 });
41 }
42 ], function(err) { /* This function gets called after
43 the two tasks have called their "task callbacks" */
44 if (err) return next(err);
45 //Here locals will be populated with `travellers` and `senders`
46 //Just like in the previous example
47 console.log(locals);
48 console.log(locals.travellers);
49 res.json(locals.travellers);
50 });
51});