Skip to content

Rating service manual

Reda Ramadan edited this page Apr 15, 2018 · 8 revisions

Using the PARASITE rating service

The rating component is implemented with supporting different objects in the system in mind. This is why a generic implementation of the rating service has been done to ensure consistency across the whole website.

Service Dependencies

Note: I don't recommend reading the documentation of these libraries, since the library documentation is outdated, and the developers made very recent changes to the library. However, their source code is simple and easy to read, so you might want to check that out for any clarification.

Service Manual

1- go to the schema of the object you want to apply rating on and add the following attribute

rating: {
        default: {
            number: 0,
            sum: 0,
            value: 0
        },
        type: {
            number: Number,
            sum: Number,
            value: Number
        }
    }

2- Add the following mongoose middleware to the schema like this example on studyPlanSchema

studyPlanSchema.post('findOneAndUpdate', function (doc) {
    var newRating = doc.rating.sum / doc.rating.number;
    this.model.update(
        { _id: doc._id },
        { $set: { 'rating.value': newRating } }
    ).exec();
});

3- Go to the module encapsulating the component you want to apply rating inside and import the new SharedModule.

4- In the HTML template of your component add the following HTML wherever you want to add rating

<app-rating [type]="'type'" [ratedID]="object._id" [rating]="object.rating.value"></app-rating>

where

  • type: The type of the object you are rating on, currently the supported objects are 'content', 'product', and 'studyPlan'
  • ratedID: The retrieved ID from mongoDB for the object that you want to rate.
  • rating: The rating of the object you want to enable rating on retrieved from mongoDB.

Note: If you want to request support for other objects, you might want to contact Omar El-Sherif

Feature Requests

For now the rating component only shows the overall rating, because it was not needed for our applications. If you want support for showing user rating for your components, or you have other ideas, make sure to contact me or Omar El-sherif for that matter, and we will easily implement it.

Authors

Clone this wiki locally