Skip to content

Commit

Permalink
Give a default value to the category query
Browse files Browse the repository at this point in the history
Relates #27
  • Loading branch information
SajedaIsmail committed Sep 24, 2019
1 parent 97b5798 commit 8bd6467
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions server/controllers/getMeals.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
const getMealsByCat = require('../database/queries/getMealsByCat');

const getMeals = (req, res, next) => {
let { category } = req.query;
let { category = 'main' } = req.query;
if (category) category = category.toLowerCase();
getMealsByCat(category)
.then((result) => (result.rows.length
? res.status(200).send({ code: 200, data: result.rows })
: res.status(400).send({
code: 400,
error: 'Bad Request: there is no such category'
})),)
? res.status(200).send({ code: 200, data: result.rows })
: res.status(400).send({
code: 400,
error: 'Bad Request: there is no such category'
})),)
.catch((err) => next(err));
};

Expand Down

0 comments on commit 8bd6467

Please sign in to comment.