Skip to content

Commit

Permalink
commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vinntt committed Feb 18, 2022
1 parent 1c962e1 commit 886dd94
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 34 deletions.
7 changes: 1 addition & 6 deletions models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const eventSchema = new Schema({
type: String,
required: true
},

creater: {
type: Schema.Types.ObjectId,
ref: 'User'
Expand All @@ -18,10 +17,7 @@ const eventSchema = new Schema({
type: String,
required: true
},
endTime: {
type: String,
required: true
},
endTime: String,
location: {
type: String,
required: true
Expand All @@ -37,7 +33,6 @@ const eventSchema = new Schema({

tags: [String],
publicId: String,
tags: [String]
});

const Event = mongoose.model('Event', eventSchema);
Expand Down
6 changes: 3 additions & 3 deletions routes/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ router.post('/new', uploadEventImages.single('img'), (req, res, next) => {
const img = req.file.path
const creater = req.session.user._id
const publicId = req.file.filename
Event.create({ img, publicId, title, creater, startDate, startTime, endTime, location, description, tags })

Event.create({ img, publicId, title, creater, startDate, startTime, endTime, location, description, tags: tags.split(",") })
.then(eventFromDB => {
console.log(eventFromDB)
res.redirect('/event/' + eventFromDB._id)
Expand Down Expand Up @@ -54,8 +55,7 @@ router.get("/:id", (req, res, next) => {
let showDelete;
if (!req.session.user) {
showDelete = false
}
else {
} else {
showDelete = req.session.user._id == event.creater._id
console.log(showDelete)
}
Expand Down
28 changes: 14 additions & 14 deletions routes/recipes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ router.post('/new', uploadRecipeImages.single('url'), (req, res, next) => {
const url = req.file.path
const creater = req.session.user._id
const publicId = req.file.filename
//filter the empty inputs
//filter the empty inputs
const filteredIngredients = ingredients.filter((ingredient) => ingredient.length > 0)
const filteredInstructions = instructions.filter((step) => step.length > 0)

//create a new recipe in the db
Recipe.create({ url, publicId, name, description, source, cooktime, servings, calories, ingredients: filteredIngredients, instructions: filteredInstructions, tags, creater })
Recipe.create({ url, publicId, name, description, source, cooktime, servings, calories, ingredients: filteredIngredients, instructions: filteredInstructions, tags: tags.split(","), creater })
.then(recipeFromDB => {
console.log(recipeFromDB)
res.redirect('/recipe/' + recipeFromDB._id)
Expand All @@ -44,15 +45,14 @@ router.get("/search", (req, res, next) => {
})
router.get("/:id", (req, res, next) => {
const id = req.params.id
//console.log(id)
//console.log(id)
Recipe.findById(id).populate('creater')
.then(recipe => {
//console.log(recipe)
let showDelete;
if (!req.session.user) {
showDelete = false
}
else {
} else {
showDelete = req.session.user._id == recipe.creater._id
console.log(showDelete)
}
Expand All @@ -61,16 +61,16 @@ router.get("/:id", (req, res, next) => {
.catch(err => next(err))
})
router.get(`/:id/edit`, (req, res, next) => {
const id = req.params.id
Recipe.findById(id)
.then(recipesFromDB => {
res.render('recipe/edit', {
recipe: recipesFromDB
const id = req.params.id
Recipe.findById(id)
.then(recipesFromDB => {
res.render('recipe/edit', {
recipe: recipesFromDB
})
})
})
.catch(err => next(err))
})
// edit recipes
.catch(err => next(err))
})
// edit recipes
router.post('/:id', uploadRecipeImages.single('url'), (req, res, next) => {
const id = req.params.id
const url = req.file.path
Expand Down
11 changes: 8 additions & 3 deletions views/event/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
{{#with event}}
<div class="event-details-box">
<div class="join-event">
<img src="{{cloudinaryResize this.img "c_fill,w_500,h_400"}}" alt="Image of the {{title}} event">
{{#if img}}
<img src="{{cloudinaryResize this.img "c_fill,w_500,h_400"}}" alt="Image of the {{title}} event">
{{/if}}
<div>
<p>⏰{{startDate}}, {{startTime}} - {{endTime}}</p>
<h1>{{title}}</h1>
<p>Created by {{creater.name}}</p>
<button type="submit" class="read-more-event">Join this event</button>
<p class="participant">{{participant}} people are going</p>
</div>
</div>

<div class="event-main-content">
<div>
<h6>📍 {{Location}}</h6>
<h6>📍{{location}}</h6>
<h6>Description: {{description}}</h6>
<h6>Tags: {{tags}}</h6>
{{#if tags}}
<h6>Tags:{{tags}}</h6>
{{/if}}
</div>

<div class="adjust-event-btn">
Expand Down
15 changes: 8 additions & 7 deletions views/event/new-event.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<h1>Create your Event 🥳</h1>
<form action="/event/new" method="POST" enctype="multipart/form-data">
<div class="mb-3">
<label for="img" class="form-label">Upload your event photo (optional)</label>
<input type="file" class="form-control" name="img">
<label for="img" class="form-label">Upload your event photo<span>*</span></label>
<input type="file" class="form-control" name="img" required>
</div>
<div class="mb-3">
<label for="title" class="form-label">Event Title<span>*</span></label>
Expand All @@ -30,11 +30,12 @@
<div class="mb-3">
<label for="location" class="form-label">Location(city)<span>*</span></label>
<select class="form-control" name="location" required>
<option>Berlin</option>
<option>Frankfurt</option>
<option>Hamburg</option>
<option>Munich</option>
<option>Others</option>
<option selected>Select City</option>
<option value="Berlin">Berlin</option>
<option value="Frankfurt">Frankfurt</option>
<option value="Hamburg">Hamburg</option>
<option value="Munich">Munich</option>
<option value="Others">Others</option>
</select>
</div>
<div class="mb-3">
Expand Down
2 changes: 1 addition & 1 deletion views/event/search.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a href="/event/{{id}}"><img src="{{cloudinaryResize img "c_fill,w_400,h_300"}}" alt="image of {{title}}" class="img-fluid"></a>
<h2><a href="/event/{{id}}">{{title}}</a></h2>
<p>⏰{{startDate}}, {{startTime}} - {{endTime}}</p>
<h6>📍 {{Location}}</h6>
<h6>📍 {{location}}</h6>
<a href="/event/{{id}}"><button class="read-more-event">Find Out More</button></a>

</div>
Expand Down

0 comments on commit 886dd94

Please sign in to comment.