forked from PsionicGeek/backend-food-ordering-system
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from PsionicGeek/master
new code
- Loading branch information
Showing
13 changed files
with
182 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
const Category = require('../models/categorySchema') | ||
const Dish = require('../models/dishSchema') | ||
|
||
//============================================================================================================================= | ||
const addDish = async(req, res)=>{ | ||
const dishObject = req.body; //the passed category name must exist | ||
|
||
//extract the category name | ||
const category_name = dishObject.category_name; | ||
delete dishObject.category_name | ||
|
||
//find the category in document | ||
const foundCategory = await Category.findOne({name : category_name}) | ||
if (foundCategory == null) | ||
res.status(401).json({msg : 'Category not found'}) | ||
dishObject.category = foundCategory; | ||
|
||
//create a new dish | ||
const newDish = await Dish.create(dishObject); | ||
|
||
if (newDish) | ||
res.status(200).json(newDish) | ||
else | ||
res.status(401).json({ message: 'Cannot add dish (Invalid or missing details)' }) | ||
} | ||
//=============================================================================================================================== | ||
const addCategory = async(req, res)=>{ | ||
const categoryObject = req.body; | ||
//create a new category | ||
const newCategory = await Category.create(categoryObject); | ||
if (newCategory) | ||
res.status(200).json(newCategory) | ||
else | ||
res.status(401).json({ message: 'Cannot add category (Invalid or missing details)' }) | ||
} | ||
//==================================================================================================================================== | ||
module.exports = { addDish, addCategory } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const jwt = require("jsonwebtoken"); | ||
|
||
const isLoggedIn = (req, res, next)=>{ | ||
|
||
const token = req.cookies.token | ||
try{ | ||
const user = jwt.verify(token, process.env.JWT_SECRET); | ||
req.user = user; | ||
} | ||
catch (err) | ||
{ | ||
return res.status(401).json({error: "Authorization required"}); | ||
} | ||
next(); | ||
}; | ||
|
||
module.exports = { isLoggedIn }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.