Closed dryutsun closed 2 years ago
Cory helped me out during lunch. Solution: You can store certain information in a nested promise chain -- at a higher scope, you can pass down variables that store information from your db query, and use them at the most inner scope where you render a page.
router.delete('/:id', isLoggedIn, (req,res)=> {
db.event.findByPk(req.params.id)
.then(foundEvent => {
let projectId = foundEvent.projectId
foundEvent.destroy()
.then(deletedEvent => {
console.log("You Removed", deletedEvent)
res.redirect(`/projects/${projectId}`)
})
})
.catch(error=>{
console.error
})
What's the problem you're trying to solve?
Non-nested routes are making it difficult to access the right information for redirects.
Post any code you think might be relevant (one fenced block per file)
[mode] event.js
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
Nothing unexpected really, but some redirects are difficult to accomplish.
What is your best guess as to the source of the problem?
Non-nested routes underdetermine how much information they require to display what they need.
What things have you already tried to solve the problem?
I've tried to rewrite the routes multiple times.