javascript - Node.js API responds with empty json -


i trying implement find() function on mobile application backend of nodejs's api. api route looks this:

app.use('/api', apiroutes); apiroutes.use('/rooms', roomroutes); roomroutes.post('/search', roomcontroller.searchrooms); 

and function in controller responding empty json time:

exports.searchrooms = function (req, res) {  room.find({     type: req.body.roomtype,     beds: req.body.beds,     max_occupancy: { $gt: req.body.guests },     cost_per_night: { $gte: req.body.pricerange.lower, $lte: req.body.pricerange.upper },     reserved: {         $not: {             $elemmatch: { from: { $lt: req.body.to.substring(0, 10) }, to: { $gt: req.body.from.substring(0, 10) } }         }      } }, function (err, rooms) {     if (err) {         res.send(err);     } else {         res.json(rooms);     } }); 

}

this function looking free rooms in hotel. , how call api application:

searchrooms(options){ return new promise(resolve => {   let headers = new headers();   headers.append('content-type', 'application/json');    this.http.post('http://localhost:8080/api/rooms/search', json.stringify(options), {headers: headers})     .map(res => res.json())     .subscribe(data => {       resolve(data);     }); }); 

}

could point me might wrong?

i think parameters may not getting delivered properly. perhaps debug controller , check. specifically, i'm not sure json.stringify(options) mapped in code tries them (e.g. $gte: req.body.pricerange.lower).


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -