Skip to content

Commit

Permalink
things
Browse files Browse the repository at this point in the history
  • Loading branch information
makon57 committed Jul 1, 2021
1 parent c56536b commit f578431
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
40 changes: 33 additions & 7 deletions public/javascripts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,41 @@ window.addEventListener("load", (event)=>{
const editBtn = document.querySelector('.edit-btn');
if (editBtn) {
editBtn.addEventListener('click', (event) => {
// event.preventDefault();
console.log("asjkbvkaj");
event.preventDefault();
const id = event.target.id
let area = document.querySelector(`#text-${id}`);
area.parentElement.innerHTML = `<textarea>${area.innerText}</textarea> <button>Save</button>`;
// editBtn.appendChild(area);
})
}
area.parentElement.innerHTML = `<textarea>${area.innerText}</textarea> <button id="save-btn">Save</button>`;

const saveBtn = document.querySelector('#save-btn');
console.log(saveBtn);
if (saveBtn) {
saveBtn.addEventListener('click', async (event) => {
// event.preventDefault();
// const id = event.target.id
// console.log(id);

});
}

const updateValue = async (event) => {
const body = event.target.value;
console.log(body);
// area.parentElement.innerHTML = `<textarea>${area.innerText}</textarea>`;

// const review = await fetch(`http://localhost:8080/review/${id}`, {
// method: "PUT",
// headers: { 'Content-Type': 'application/json' },
// body: JSON.stringify({body}),
// });
// const update = await review.json();

}

area.addEventListener('change', updateValue)


})
}


})
});
30 changes: 25 additions & 5 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,39 @@ router.post('/trail/:id(\\d+)', asyncHandler(async(req, res, next) => {
// }
// }));

// router.put(
// "/trail/:id(\\d+)",
// asyncHandler(async (req, res, next) => {
// const review = await db.Review.findOne({ where: { id: trailId, userId: req.session.auth.userId } });
// console.log(review);
// if (req.user.id !== review.userId) {
// const err = new Error("Unauthorized");
// err.status = 401;
// err.message = "You are not authorized to edit this tweet.";
// err.title = "Unauthorized";
// throw err;
// } else if (review) {
// await review.update({ text: req.body.text });
// }
// })
// );

router.put(
"/trail/:id(\\d+)",
"/review/:id(\\d+)",
asyncHandler(async (req, res, next) => {
const review = await Review.findOne({ where: { id: req.params.id } });

if (req.user.id !== review.userId) {
const id = req.params.id;
const review = await db.Review.findByPk(id);
console.log(review);
if (req.session.auth.userId !== review.userId) {
const err = new Error("Unauthorized");
err.status = 401;
err.message = "You are not authorized to edit this tweet.";
err.title = "Unauthorized";
throw err;
} else if (review) {
await review.update({ text: req.body.text });
console.log(req.body.body);
await review.update({ text: req.body.body });
res.json(review)
}
})
);
Expand Down

0 comments on commit f578431

Please sign in to comment.