Skip to content

Commit

Permalink
Merge pull request #17 from HSNM2/feature/20230523_John_user_owned_co…
Browse files Browse the repository at this point in the history
…urse

feat: 新增 課程持有確認
  • Loading branch information
paperhsiaooo committed May 23, 2023
2 parents 6adac8f + ddd6c50 commit d011756
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
36 changes: 36 additions & 0 deletions controllers/userController/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,39 @@ exports.identity = {
}
}
}

exports.ownedCourse = {
post: async (req, res) => {
try {
const { userId } = req
const courseId = req.body.id

const user = await User.findByPk(userId, {
include: [
{
model: Course,
where: { id: courseId },
required: true
}
]
})

if (user) {
return res.json({
status: true,
message: '擁有此課程',
isOwned: true
})
} else {
return res.json({
statue: true,
message: '尚未擁有此課程',
isOwned: false
})
}
} catch (error) {
console.error(error)
res.json(errorTemplateFun(error))
}
}
}
1 change: 1 addition & 0 deletions routers/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ router.delete('/tag/:courseId', [authJwt.verifyToken], userController.favorite.d
router.get('/tag/userFavorite', [authJwt.verifyToken], userController.getFavorite.get)
router.get('/identity', [authJwt.verifyToken], userController.identity.get)
router.post('/identity', [authJwt.verifyToken], userController.identity.post)
router.post('/ownedCourse/check', [authJwt.verifyToken], userController.ownedCourse.post)

module.exports = router

0 comments on commit d011756

Please sign in to comment.