-
- previousRate.save(options).asCallback(function (err) {
- return callback(err, t, likesToIncrement, dislikesToIncrement)
- })
- } else { // There was not a previous rate, insert a new one
- const query = {
- userId: userInstance.id,
- videoId: videoInstance.id,
- type: rateType
- }
-
- db.UserVideoRate.create(query, options).asCallback(function (err) {
- return callback(err, t, likesToIncrement, dislikesToIncrement)
- })
- }
- },
-
- function updateVideoAttributeDB (t, likesToIncrement, dislikesToIncrement, callback) {
- const options = { transaction: t }
- const incrementQuery = {
- likes: likesToIncrement,
- dislikes: dislikesToIncrement
- }
-
- // Even if we do not own the video we increment the attributes
- // It is usefull for the user to have a feedback
- videoInstance.increment(incrementQuery, options).asCallback(function (err) {
- return callback(err, t, likesToIncrement, dislikesToIncrement)
- })
- },
-
- function sendEventsToFriendsIfNeeded (t, likesToIncrement, dislikesToIncrement, callback) {
- // No need for an event type, we own the video
- if (videoInstance.isOwned()) return callback(null, t, likesToIncrement, dislikesToIncrement)
-
- const eventsParams = []
-
- if (likesToIncrement !== 0) {
- eventsParams.push({
- videoId: videoInstance.id,
- type: REQUEST_VIDEO_EVENT_TYPES.LIKES,
- count: likesToIncrement
- })