Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const getAllStock = (req, res) => {
- const urlObj = url.parse(req.url, true);
- const query = urlObj.query;
- if (query.name == null) {
- res.status(200).end('no bar with such name')
- }
- else {
- mongoose.connect(mongourl, options)
- .then(async () => {
- let result = await bar.find({name:query.name}, (err) => {
- if (err)
- throw err;
- });
- if (result) {
- let tempDrinkArr = []
- console.log('this is the stock:\n\n' + result);
- console.log('this is the name:\n' + result.name);
- for (let i = 0; i < result.stock.length; i++) {
- tempDrinkArr.push(`${result.stock[i].bottles} bottles of ${result.stock[i].name} in stock`);
- }
- res.writeHead(200);
- res.end(tempDrinkArr.toString());
- }
- else {
- res.end('no drinks in stock');
- }
- })
- .catch(err => {
- console.error('some error occurred', err)
- res.end(err.message);
- })
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement