Tried Validation - didnt succeed
This commit is contained in:
29
app.js
29
app.js
@@ -16,7 +16,7 @@ mongoose.connect(
|
|||||||
process.env.DB_PASS +
|
process.env.DB_PASS +
|
||||||
"@menui-database.9quwf.mongodb.net/<dbname>?retryWrites=true&w=majority",
|
"@menui-database.9quwf.mongodb.net/<dbname>?retryWrites=true&w=majority",
|
||||||
{ useNewUrlParser: true, useUnifiedTopology: true },
|
{ useNewUrlParser: true, useUnifiedTopology: true },
|
||||||
(err) => {
|
err => {
|
||||||
if (err) console.log(err);
|
if (err) console.log(err);
|
||||||
else console.log("Connected To Database");
|
else console.log("Connected To Database");
|
||||||
}
|
}
|
||||||
@@ -24,7 +24,7 @@ mongoose.connect(
|
|||||||
|
|
||||||
// GET A PARTICULAR RESTAURANT //
|
// GET A PARTICULAR RESTAURANT //
|
||||||
|
|
||||||
app.get("/restaurant/:restaurantId", function (req, res) {
|
app.get("/restaurant/:restaurantId", function(req, res) {
|
||||||
Restaurant.findById(req.params.restaurantId, (err, data) => {
|
Restaurant.findById(req.params.restaurantId, (err, data) => {
|
||||||
if (err) res.send(err);
|
if (err) res.send(err);
|
||||||
else res.send(data);
|
else res.send(data);
|
||||||
@@ -33,7 +33,7 @@ app.get("/restaurant/:restaurantId", function (req, res) {
|
|||||||
|
|
||||||
// GET RESTAURANTS IN A SPECIFIED CITY //
|
// GET RESTAURANTS IN A SPECIFIED CITY //
|
||||||
|
|
||||||
app.get("/city/:cityName", function (req, res) {
|
app.get("/city/:cityName", function(req, res) {
|
||||||
Restaurant.find({ city: decodeURI(req.params.cityName) }, (err, data) => {
|
Restaurant.find({ city: decodeURI(req.params.cityName) }, (err, data) => {
|
||||||
if (err) res.send(err);
|
if (err) res.send(err);
|
||||||
else res.send(data);
|
else res.send(data);
|
||||||
@@ -49,20 +49,26 @@ app.post("/restaurant", (req, res) => {
|
|||||||
city: req.body.city,
|
city: req.body.city,
|
||||||
imgUrl: req.body.imgUrl,
|
imgUrl: req.body.imgUrl,
|
||||||
workingHours: req.body.workingHours,
|
workingHours: req.body.workingHours,
|
||||||
hidden: req.body.hidden,
|
hidden: req.body.hidden
|
||||||
});
|
});
|
||||||
restaurant.save().catch((err) => console.log(err));
|
restaurant.save().catch(err => console.log(err));
|
||||||
res.status(201).json({
|
res.status(201).json({
|
||||||
message: "Restaurant Created",
|
message: "Restaurant Created",
|
||||||
addedRestaurant: restaurant,
|
addedRestaurant: restaurant
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ADD NEW DISH //
|
// ADD NEW DISH //
|
||||||
|
|
||||||
app.post("/dish", (req, res) => {
|
app.post("/dish", (req, res) => {
|
||||||
const restaurantId = req.body.restaurantId;
|
const getRestaurantId = async () => {
|
||||||
const userData = req.body.userData;
|
const result = await Restaurant.findById(req.body.restaurantId).exec();
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const restaurantId = getRestaurantId();
|
||||||
|
|
||||||
|
/*const userData = validators.validateUser(req.body.userId);
|
||||||
const dish = new Dish({
|
const dish = new Dish({
|
||||||
_id: new mongoose.Types.ObjectId(),
|
_id: new mongoose.Types.ObjectId(),
|
||||||
name: req.body.name,
|
name: req.body.name,
|
||||||
@@ -78,11 +84,12 @@ app.post("/dish", (req, res) => {
|
|||||||
eggs: req.body.eggs,
|
eggs: req.body.eggs,
|
||||||
seaFood: req.body.seaFood,
|
seaFood: req.body.seaFood,
|
||||||
peanuts: req.body.peanuts,
|
peanuts: req.body.peanuts,
|
||||||
sesame: req.body.sesame,
|
sesame: req.body.sesame
|
||||||
},
|
},
|
||||||
vegan: req.body.vegan,
|
vegan: req.body.vegan,
|
||||||
vegetarian: req.body.vegetarian,
|
vegetarian: req.body.vegetarian
|
||||||
});
|
});*/
|
||||||
|
res.send(restaurantId);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen(port, () => console.log("Menui back-end is listening at: " + port));
|
app.listen(port, () => console.log("Menui back-end is listening at: " + port));
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
|
const Restaurant = require("./models/restaurant");
|
||||||
|
const Dish = require("./models/dish");
|
||||||
|
const User = require("./models/users");
|
||||||
|
|
||||||
function validateRestaurant(id) {
|
function validateRestaurant(id) {
|
||||||
return true;
|
/*Restaurant.findById(id, (err, data) => {
|
||||||
|
if (err) return err;
|
||||||
|
else return data;
|
||||||
|
});*/
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
function validateUser(id) {
|
||||||
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.validateRestaurant = validateRestaurant;
|
exports.validateRestaurant = validateRestaurant;
|
||||||
|
exports.validateUser = validateUser;
|
||||||
|
|||||||
Reference in New Issue
Block a user