limited ratings so that only one per user and restyled the comment frame for a user

This commit is contained in:
zipben 2025-06-04 14:38:51 +00:00
parent c5ddede56e
commit 111742cf99
3 changed files with 58 additions and 33 deletions

View file

@ -1170,7 +1170,6 @@ class LibraryItemController {
}
/**
*
* @param {RequestWithUser} req
* @param {Response} res
* @param {NextFunction} next
@ -1193,6 +1192,11 @@ class LibraryItemController {
}
}
// Allow comment operations for all authenticated users
if (req.path.includes('/comments')) {
return next()
}
if (req.path.includes('/play')) {
// allow POST requests using /play and /play/:episodeId
} else if (req.method == 'DELETE' && !req.user.canDelete) {
@ -1240,6 +1244,18 @@ class LibraryItemController {
*/
async addComment(req, res) {
try {
// Check if user already has a comment for this item
const existingComment = await Database.commentModel.findOne({
where: {
libraryItemId: req.params.id,
userId: req.user.id
}
})
if (existingComment) {
return res.status(400).json({ error: 'You have already submitted a review for this item' })
}
const comment = await Database.commentModel.create({
text: req.body.text,
rating: req.body.rating,