Skip to content

Commit

Permalink
seeding reviews and users
Browse files Browse the repository at this point in the history
  • Loading branch information
makon57 committed Jul 1, 2021
1 parent a60fd2e commit 7a9d548
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 29 deletions.
22 changes: 14 additions & 8 deletions db/seeders/20210629195804-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@

module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.bulkInsert('Users', [{
id: 1,
username: "demoUser",
email: "demo@demo.user",
password: "D3mo!",
createdAt: new Date(),
updatedAt: new Date()
}], {});
return queryInterface.bulkInsert('Users', [
{username: "demoUser", email: "demo@demo.user", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "joyntables", email: "JP@wat.com", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "recrecurecursion", email: "recur@re.com", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "ToastingTests", email: "TT@aol.com", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "I_Still_Use_AOL", email: "winner@aol.com", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "granny", email: "QueenGranny@yahoo.com", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "Gerald_Kingston", email: "Gerry@aol.com", password: "D3mo!", createdAt: new Date (), updatedAt: new Date()},
{username: "Manna", email: "Manna@manna.com", password: "1!Manna", createdAt: new Date (), updatedAt: new Date()},
{username: "Lema", email: "Lema@lema.com", password: "1!Lema", createdAt: new Date (), updatedAt: new Date()},
{username: "Simon", email: "Simon@simon.com", password: "1!Simon", createdAt: new Date (), updatedAt: new Date()},
{username: "Jacob", email: "Jacob@jacob.com", password: "1!Jacob", createdAt: new Date (), updatedAt: new Date()},
{username: "Javier-The-Goat", email: "Javier@aa.com", password: "1!Mortiz", createdAt: new Date (), updatedAt: new Date()}
], {});
},

down: (queryInterface, Sequelize) => {
Expand Down
54 changes: 42 additions & 12 deletions db/seeders/20210630025729-reviews.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion public/javascripts/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
window.addEventListener("load", (event)=>{
console.log("hello from javascript!")
})

const writeReview = document.querySelector('.rate-btn hi');

writeReview.addEventListener('click', (event) => {
event.preventDefault();

})

})
36 changes: 35 additions & 1 deletion routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,47 @@ router.get('/', csrfProtection, asyncHandler(async(req, res) => {
router.get('/trail/:id(\\d+)', csrfProtection, asyncHandler(async(req, res, next) => {
const trailId = parseInt(req.params.id, 10);
const trail = await db.Trail.findByPk(trailId);
const reviews = await db.Reviews.findAll({ where: trailId})
res.render('trail-detail', {
title: "Park Detail",
trail
trail,
reviews
});
}));



router.post('/trail/:id(\\d+)', csrfProtection, asyncHandler(async(req, res, next) => {
const { text } = req.body;
const review = await Review.create({ text, userId: req.user.id, trailId:req.trail.id, createdAt: req.review.createdAt });
res.render('trail-detail', ({ review }));
}));

// router.put('/:id(\\d+)', validateTweet, handleValidationErrors,asyncHandler(async(req, res, next) => {
// const tweetId = req.params.id;
// const tweet = await Tweet.findByPk(tweetId);

// if (tweet) {
// await tweet.update({ message: req.body.message });
// res.json({ tweet });
// } else {
// next(tweetNotFound(tweetId));
// }
// }));

// router.delete('/:id(\\d+)', asyncHandler(async(req, res, next) => {
// const tweetId = req.params.id;
// const tweet = await Tweet.findByPk(tweetId);

// if (tweet) {
// await tweet.destroy();
// res.status(201).end();
// } else {
// next(tweetNotFound(tweetId));
// }
// }));


router.post('/', (req, res) => {
logoutUser(req, res);
res.redirect('/login');
Expand Down
22 changes: 15 additions & 7 deletions views/trail-detail.pug
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//- append head
//- link(rel="stylesheet" href="/stylesheets/details.css")
//- block content
//- header
//- header
//- div
//- nav(id="nav" class="nav-bar")
//- form(action="/" method="get" id="demo" class="demo")
Expand All @@ -16,7 +16,7 @@
//- div(class='container')
//- p(class=`name`)= trail.name
//- img(src=`../trails/trail-${trail.id}.jpg` alt=`${trail.name}` class=`trail-image-${trail.id}`)
//- p(class=`details`)= trail.description
//- p(class=`details`)= trail.description
//- div(class='btn-container')
//- form(action="/" method="get" id="demo" class="demo")
//- button(type="submit" class="rate-btn hi") Write a Review
Expand All @@ -41,21 +41,29 @@ block content
button(type="submit" class="logout-btn home") Home
form(action="/" method="post" id="demo" class="demo")
button(type="submit" class="logout-btn logout") Logout

else
form(action="/" method="post" id="demo" class="demo")
button(type="submit" class="login-btn") Login
form(action="/" method="post" id="demo" class="demo")
button(type="submit" class="sign-btn") Sign Up
div
h1 MixTrail
h1 MixTrail
div(class='container')
div(class='top-container')
p(class=`name`)= trail.name
img(src=`../trails/trail-${trail.id}.jpg` alt=`${trail.name}` class=`trail-image-${trail.id}`)
p(class=`details`)= trail.description
p(class=`details`)= trail.description
div(class='btn-container')
form(action="/trailList" method="post" id="demo" class="demo")
button(type="submit" class="add-btn hi") Add to TrailList
form(action=`/trail/${trail.id}/review` method="post" id="demo" class="demo")
button(type="submit" class="rate-btn hi") Write a Review
form(action=`/trail/${trail.id}` method="post" id="demo" class="demo")
button(type="submit" class="rate-btn hi") Write a Review
div(class="list-reviews")
each review in reviews
div
p= review.text
p= review.createdAt
//- div(class="review-container")
//- form(action="/" method="post" class="")
//- textarea(name="text")

0 comments on commit 7a9d548

Please sign in to comment.