Closed JuanR9910 closed 2 years ago
Which route is the one that should be sending comments to the EJS?
The post route is the one that's having issues currently. For some reason it's not grabbing the gameId from the url parameters, when we console log req.params.id
it just prints :id
so the comment model can't populate
Posting is solved! Tom is now working with Juan to display the comments.
What stack are you using?
(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)
Nodejs, Postgres, Psql
What's the problem you're trying to solve?
Comment that user submitted shows in terminal but doesn't display on webpage
Post any code you think might be relevant (one fenced block per file)
``Review.js
require("dotenv").config()
const { render } = require("ejs");
const db = require("../models");
const express = require("express")
const router = express.Router();
const axios = require('axios')
// GET route
router.get('/:id', (req, res) => {
axios.get(
https://rawg.io/api/games/${req.params.id}?key=${process.env.RAWG_API_KEY})
.then(apiRes => {
console.log('this is apiRes', apiRes.data)
const gameData = apiRes.data
console.log("THIS IS OUR CONSOLE LOG", gameData)
res.render('review.ejs', {gameData:gameData})
})
.catch((error) => {
res.status(400).render('main404')
})
})
//POST route - making user post a review under a game
router.post('/:id', (req, res) => {
const gameId = req.params.id
const user = res.locals.currentUser
console.log(gameId)
console.log(req.body.content)
console.log(res.locals.currentUser)
// db.comment.create({
// gameId: gameId,
// content: req.body.content,
// userId: user.id
// })
// .then((post) => {
// res.redirect('/review/:id')
// })
// .catch((error) => {
// res.status(400)
// })
})
// router.put('/review.ejs',(req, res) => {
// db.user.put({
// gameid: req.body.title,
// content: req.body.content,
// userid: req.body.userid
`// })
// .then((put) => {
// res.redirect('/review.ejs')
// })
// .catch((error) => {
// res.status(400).render('main/404')
// })
// })
// router.delete('/review.ejs', (req, res) => {
// db.user.delete({
// gameid: req.body.title,
// content: req.body.content,
// userid: req.body.userid
// })
// .then((delete) => {
// res.redirect('/review.ejs')
// })
// .catch((error) => {
// res.status(400).render('main/404')
// })
// })
// router.get('/:id', (req, res) => {
// db.user.findOne({
// where: { id: req.params.id },
// include: [db.review]
// })
// .then((review) => {
// if(!review) throw Error()
// console.log(review.user)
// res.render('/views/review'), {user: review}
// }).catch((error) => {
// console.log(error)
// res.status(400).render('main/404')
// })
// })
// Create other routes for the review page
module.exports = router;