Skip to content

Commit

Permalink
Merge pull request #4 from Antarctic-penguin/R04
Browse files Browse the repository at this point in the history
將推文時間轉換成幾小時前格式
  • Loading branch information
blade8128ch authored Nov 10, 2023
2 parents aeec7d7 + 2fcfb5b commit 1dc0991
Show file tree
Hide file tree
Showing 7 changed files with 148 additions and 72 deletions.
39 changes: 39 additions & 0 deletions controllers/apis/user-controller.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const jwt = require('jsonwebtoken')
const { Tweet } = require('../../models')
const userController = {
signIn: (req, res, next) => {
try {
Expand All @@ -15,6 +16,44 @@ const userController = {
} catch (err) {
next(err)
}
},
addLike: (req, res, next) => {
const { tweetId } = req.params
return Promise.all([
Tweet.findByPk(tweetId),
Like.findOne({
where: {
userId: req.user.id,
tweetId
}
})
])
.then(([tweet, like]) => {
if (!tweet) throw new Error("tweet didn't exist!")
if (like) throw new Error('You have favorited this tweet!')

return Like.create({
userId: req.user.id,
tweet
})
})
.then(() => res.redirect('back'))
.catch(err => next(err))
},
removeLike: (req, res, next) => {
return Like.findOne({
where: {
userId: req.user.id,
restaurantId: req.params.restaurantId
}
})
.then(like => {
if (!like) throw new Error("You haven't favorited this restaurant")

return like.destroy()
})
.then(() => res.redirect('back'))
.catch(err => next(err))
}
}
module.exports = userController
1 change: 0 additions & 1 deletion middleware/api-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const authenticated = (req, res, next) => {
})(req, res, next)
}
const authenticatedAdmin = (req, res, next) => {
console.log(helpers.getUser(req))
if (helpers.getUser(req) && helpers.getUser(req).role === 'admin') return next()
return res.status(403).json({ status: 'error', message: 'permission denied' })
}
Expand Down
Loading

1 comment on commit 1dc0991

@blade8128ch
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

like路由須再修正

Please sign in to comment.