Skip to content

Commit

Permalink
Merge pull request #25 from pnijhara/model-patch-2
Browse files Browse the repository at this point in the history
model: FoodUp and user association
  • Loading branch information
pnijhara authored Jun 12, 2020
2 parents 4c50827 + 626c96d commit 7817b35
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
21 changes: 14 additions & 7 deletions models/foodup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@ const mongoose = require("mongoose")
const foodDataSchema = new mongoose.Schema({
name: String,
description: String,
image: String,
comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
]
image: String,
author: {
id: {
type: mongoose.Schema.Types.ObjectId,
ref: "User"
},
username: String
},
comments: [
{
type: mongoose.Schema.Types.ObjectId,
ref: "Comment"
}
]
})

const foodData = mongoose.model("foodData", foodDataSchema)
Expand Down
7 changes: 6 additions & 1 deletion routes/FoodUp.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ router.post("/FoodUp", isLoggedIn, function(req, res){
const name = req.body.name
const description = req.body.description
const image = req.body.image
const author = {
id: req.user._id,
username: req.user.username
}
const newfoodData = {
name: name,
description: description,
image: image
image: image,
author: author
}
// foodData.push(newfoodData)
foodData.create(newfoodData, function(err, newfoodData){
Expand Down
4 changes: 4 additions & 0 deletions views/food-up/show.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<h4><a><%= foundFoodData.name %></a></h4>
<br>
<p><%= foundFoodData.description%></p>
<br>
<p>
<em>Submitted by <%= foundFoodData.author.username %> </em>
</p>
</div>
</div>
<div class="well">
Expand Down

0 comments on commit 7817b35

Please sign in to comment.