Skip to content

Commit 1733742

Browse files
committed
Fix: update post hashtag
1 parent f2295b9 commit 1733742

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

ch7/back/routes/post.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,15 @@ router.delete('/:postId/like', isLoggedIn, async (req, res, next) => { // DELETE
251251
router.patch('/:postId', isLoggedIn, async (req, res, next) => { // PATCH /post/10
252252
const hashtags = req.body.content.match(/#[^\s#]+/g);
253253
try {
254-
const post = await Post.update({
254+
await Post.update({
255255
content: req.body.content
256256
}, {
257257
where: {
258258
id: req.params.postId,
259259
UserId: req.user.id,
260260
},
261261
});
262+
const post = await Post.findOne({ where: { id: req.params.postId }});
262263
if (hashtags) {
263264
const result = await Promise.all(hashtags.map((tag) => Hashtag.findOrCreate({
264265
where: { name: tag.slice(1).toLowerCase() },

https/back/routes/post.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,15 @@ router.delete('/:postId/like', isLoggedIn, async (req, res, next) => { // DELETE
251251
router.patch('/:postId', isLoggedIn, async (req, res, next) => { // PATCH /post/10
252252
const hashtags = req.body.content.match(/#[^\s#]+/g);
253253
try {
254-
const post = await Post.update({
254+
await Post.update({
255255
content: req.body.content
256256
}, {
257257
where: {
258258
id: req.params.postId,
259259
UserId: req.user.id,
260260
},
261261
});
262+
const post = await Post.findOne({ where: { id: req.params.postId }});
262263
if (hashtags) {
263264
const result = await Promise.all(hashtags.map((tag) => Hashtag.findOrCreate({
264265
where: { name: tag.slice(1).toLowerCase() },

0 commit comments

Comments
 (0)