Add review and rating features with sorting and filtering options

- Implemented a new ReviewController to handle review creation, updates, and retrieval for library items.
- Added pagination, sorting, and filtering capabilities for reviews in the API.
- Updated frontend components to support review display, including a new ReviewsTable and enhanced ratings UI.
- Introduced new strings for user interface elements related to reviews and ratings.
- Added tests for the ReviewController and Review model to ensure functionality and validation.
- Enabled the option to toggle the review feature in server settings.
This commit is contained in:
fannta1990 2026-02-09 21:08:18 +08:00
parent e4e2770fbd
commit 41e8906312
12 changed files with 603 additions and 43 deletions

View file

@ -1,18 +1,32 @@
const { DataTypes, Model } = require('sequelize')
/**
* @typedef ReviewJSON
* @property {string} id
* @property {number} rating
* @property {string} reviewText
* @property {string} userId
* @property {string} libraryItemId
* @property {number} updatedAt
* @property {number} createdAt
* @property {Object} [user]
* @property {string} user.id
* @property {string} user.username
*/
class Review extends Model {
constructor(values, options) {
super(values, options)
/** @type {UUIDV4} */
/** @type {string} */
this.id
/** @type {number} */
this.rating
/** @type {string} */
this.reviewText
/** @type {UUIDV4} */
/** @type {string} */
this.userId
/** @type {UUIDV4} */
/** @type {string} */
this.libraryItemId
/** @type {Date} */
this.updatedAt
@ -20,6 +34,12 @@ class Review extends Model {
this.createdAt
}
/**
* Initialize the Review model and associations.
* A user can have only one review per library item.
*
* @param {import('sequelize').Sequelize} sequelize
*/
static init(sequelize) {
super.init(
{
@ -62,6 +82,11 @@ class Review extends Model {
Review.belongsTo(libraryItem)
}
/**
* Convert to the old JSON format for the browser.
*
* @returns {ReviewJSON}
*/
toOldJSON() {
return {
id: this.id,
@ -79,4 +104,4 @@ class Review extends Model {
}
}
module.exports = Review
module.exports = Review