From 9b059521f7006aad2e40f8a3024c525e60381095 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 13:51:13 +0300 Subject: [PATCH 01/30] Move permisisons to own file --- apis/collection/backend.js | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/apis/collection/backend.js b/apis/collection/backend.js index 6fa7c150e1..973a899c00 100644 --- a/apis/collection/backend.js +++ b/apis/collection/backend.js @@ -658,44 +658,6 @@ Schemas.ApiBackendsSchema = new SimpleSchema({ ApiBackends.attachSchema(Schemas.ApiBackendsSchema); -ApiBackends.allow({ - insert: function () { - return true; - }, - update: function (userId, apiBackendDoc) { - // Save ID of API Backend - const apiBackendId = apiBackendDoc._id; - // Get API backend with ID - const apiBackend = ApiBackends.findOne(apiBackendId); - // Check if current user can edit API Backend - let currentUserCanEdit = apiBackend.currentUserCanEdit(); - - if (currentUserCanEdit) { - // User is allowed to perform action - return true; - } else { - // User is not allowded to perform action - return false; - } - }, - remove: function (userId, apiBackendDoc) { - // Save ID of API Backend - const apiBackendId = apiBackendDoc._id; - // Get API backend with ID - const apiBackend = ApiBackends.findOne(apiBackendId); - // Check if current user can edit API Backend - let currentUserCanEdit = apiBackend.currentUserCanEdit(); - - if (currentUserCanEdit) { - // User is allowed to perform action - return true; - } else { - // User is not allowded to perform action - return false; - } - } -}); - SimpleSchema.messages({ // RegEx messages regEx: [ From d682d0711c145cc5bbad679694e3bab70b8aa0f8 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 13:51:35 +0300 Subject: [PATCH 02/30] Move allow rules; create initial deny rules --- apis/collection/permissions.js | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 apis/collection/permissions.js diff --git a/apis/collection/permissions.js b/apis/collection/permissions.js new file mode 100644 index 0000000000..7ddf45cb2d --- /dev/null +++ b/apis/collection/permissions.js @@ -0,0 +1,46 @@ +ApiBackends.allow({ + insert: function () { + return true; + }, + update: function (userId, apiBackendDoc) { + // Save ID of API Backend + const apiBackendId = apiBackendDoc._id; + // Get API backend with ID + const apiBackend = ApiBackends.findOne(apiBackendId); + // Check if current user can edit API Backend + let currentUserCanEdit = apiBackend.currentUserCanEdit(); + + if (currentUserCanEdit) { + // User is allowed to perform action + return true; + } else { + // User is not allowded to perform action + return false; + } + }, + remove: function (userId, apiBackendDoc) { + // Save ID of API Backend + const apiBackendId = apiBackendDoc._id; + // Get API backend with ID + const apiBackend = ApiBackends.findOne(apiBackendId); + // Check if current user can edit API Backend + let currentUserCanEdit = apiBackend.currentUserCanEdit(); + + if (currentUserCanEdit) { + // User is allowed to perform action + return true; + } else { + // User is not allowded to perform action + return false; + } + } +}); + +ApiBackends.deny({ + insert () { + return false; + }, + update () { + return false; + } +}); From c0b961ca1892b8134f190d06230155e9ac6665d2 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 13:51:54 +0300 Subject: [PATCH 03/30] Add averageRating field --- apis/collection/backend.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apis/collection/backend.js b/apis/collection/backend.js index 973a899c00..e37ef37373 100644 --- a/apis/collection/backend.js +++ b/apis/collection/backend.js @@ -653,6 +653,14 @@ Schemas.ApiBackendsSchema = new SimpleSchema({ type: "hidden", label: false } + }, + averageRating: { + type: Number, + decimal: true, + autoform: { + type: "hidden", + label: false + } } }); From 1a664acad2ab557cac0e2d258af8d1df7aa3af1e Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 13:52:16 +0300 Subject: [PATCH 04/30] Add bookmarkCount field --- apis/collection/backend.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apis/collection/backend.js b/apis/collection/backend.js index e37ef37373..124897b543 100644 --- a/apis/collection/backend.js +++ b/apis/collection/backend.js @@ -661,6 +661,13 @@ Schemas.ApiBackendsSchema = new SimpleSchema({ type: "hidden", label: false } + }, + bookmarkCount: { + type: Number, + autoform: { + type: "hidden", + label: false + } } }); From 5e4262fd9d1372a11169c765f57b07db2a75011d Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 13:54:12 +0300 Subject: [PATCH 05/30] Don't allow averageRating or bookmarkCount to be set by user --- apis/collection/permissions.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/apis/collection/permissions.js b/apis/collection/permissions.js index 7ddf45cb2d..43cdace8b4 100644 --- a/apis/collection/permissions.js +++ b/apis/collection/permissions.js @@ -38,9 +38,15 @@ ApiBackends.allow({ ApiBackends.deny({ insert () { - return false; + // Don't allow user to set average rating or bookmark count fields + if (_.contains(fields, "averageRating") || _.contains(fields, "bookmarkCount")) { + return true; + } }, update () { - return false; + // Don't allow user to set average rating or bookmark count fields + if (_.contains(fields, "averageRating") || _.contains(fields, "bookmarkCount")) { + return true; + } } }); From 40ee64390b12f9843fa11b61070712b760769e69 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:00:34 +0300 Subject: [PATCH 06/30] Add getAverageRating and getBookmarkCount helpers --- apis/collection/backend.js | 45 +++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/apis/collection/backend.js b/apis/collection/backend.js index 124897b543..546a5638ce 100644 --- a/apis/collection/backend.js +++ b/apis/collection/backend.js @@ -684,6 +684,32 @@ SimpleSchema.messages({ }); ApiBackends.helpers({ + 'getAverageRating' () { + // Fetch all ratings + var apiBackendRatings = ApiBackendRatings.find({ + apiBackendId: this._id + }).fetch(); + + // If ratings exist + if (apiBackendRatings) { + // Create array containing only rating values + var apiBackendRatingsArray = _.map(apiBackendRatings, function (rating) { + // get only the rating value; omit User ID and API Backend ID fields + return rating.rating; + }); + + // Get the average (mean) value for API Backend ratings + var apiBackendRatingsAverage = ss.mean(apiBackendRatingsArray); + + return apiBackendRatingsAverage; + } + }, + 'getBookmarksCount' () { + // Get API Backend ID + const apiBackendId = this._id; + + return ApiBookmarks.find({apiBackendId}).count(); + }, 'getRating': function () { // Get API Backend ID apiBackendId = this._id; @@ -703,24 +729,7 @@ ApiBackends.helpers({ // Otherwise, get average rating - // Fetch all ratings - var apiBackendRatings = ApiBackendRatings.find({ - apiBackendId: apiBackendId - }).fetch(); - - // If ratings exist - if (apiBackendRatings) { - // Create array containing only rating values - var apiBackendRatingsArray = _.map(apiBackendRatings, function (rating) { - // get only the rating value; omit User ID and API Backend ID fields - return rating.rating; - }); - - // Get the average (mean) value for API Backend ratings - var apiBackendRatingsAverage = ss.mean(apiBackendRatingsArray); - - return apiBackendRatingsAverage; - } + return this.getAverageRating(); }, currentUserCanEdit: function() { // Get current userId From 437cc3bfafc67a7e122b4fe8a9d8877d20a5d93c Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:22:50 +0300 Subject: [PATCH 07/30] Move helpers to own file --- apis/collection/backend.js | 88 -------------------------------------- 1 file changed, 88 deletions(-) diff --git a/apis/collection/backend.js b/apis/collection/backend.js index 546a5638ce..7d098c3c95 100644 --- a/apis/collection/backend.js +++ b/apis/collection/backend.js @@ -1,5 +1,3 @@ -import ss from 'simple-statistics'; - ApiBackends = new Mongo.Collection('apiBackends'); // RegEx constants @@ -682,89 +680,3 @@ SimpleSchema.messages({ // update password form "updatePassword_passwordsMismatch": "Passwords do not match" }); - -ApiBackends.helpers({ - 'getAverageRating' () { - // Fetch all ratings - var apiBackendRatings = ApiBackendRatings.find({ - apiBackendId: this._id - }).fetch(); - - // If ratings exist - if (apiBackendRatings) { - // Create array containing only rating values - var apiBackendRatingsArray = _.map(apiBackendRatings, function (rating) { - // get only the rating value; omit User ID and API Backend ID fields - return rating.rating; - }); - - // Get the average (mean) value for API Backend ratings - var apiBackendRatingsAverage = ss.mean(apiBackendRatingsArray); - - return apiBackendRatingsAverage; - } - }, - 'getBookmarksCount' () { - // Get API Backend ID - const apiBackendId = this._id; - - return ApiBookmarks.find({apiBackendId}).count(); - }, - 'getRating': function () { - // Get API Backend ID - apiBackendId = this._id; - - // Check if user is logged in - if (Meteor.userId()) { - // Check if user has rated API Backend - var userRating = ApiBackendRatings.findOne({ - userId: Meteor.userId(), - apiBackendId: apiBackendId - }); - - if (userRating) { - return userRating.rating; - } - } - - // Otherwise, get average rating - - return this.getAverageRating(); - }, - currentUserCanEdit: function() { - // Get current userId - var userId = Meteor.userId(); - - // Check that user is logged in - if( userId ) { - // Check if user is API manager - var isManager = _.contains(this.managerIds, userId); - - if (isManager) { - return true; - } - - // Check if user is administrator - var isAdmin = Roles.userIsInRole(userId, ['admin']); - - if (isAdmin) { - return true; - } - } else { - // User is not logged in - return false; - } - }, - currentUserIsManager: function () { - // Get current User ID - var userId = Meteor.userId(); - - // Get Manager IDs array from API Backend document - var managerIds = this.managerIds; - - // Check if User ID is in Manager IDs array - var isManager = _.contains(managerIds, userId); - - return isManager; - } -}); From 84c874e1ca5fc9142493c6f59b0d57b013f6ff98 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:23:05 +0300 Subject: [PATCH 08/30] Cleanup --- bookmarks/server/methods.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/bookmarks/server/methods.js b/bookmarks/server/methods.js index f961c34a2c..df9df65eea 100644 --- a/bookmarks/server/methods.js +++ b/bookmarks/server/methods.js @@ -6,10 +6,10 @@ Meteor.methods({ // object to store currentUserId and the Api ID var userBookmarks = {userId: currentUserId, apiIds: apiBackendIds}; - + // If possible, get the bookmarks for current user. var existingUserBookmarks = ApiBookmarks.findOne({userId: currentUserId}); - + // Check if user has existing bookmarks if (existingUserBookmarks) { // Get an array of bookmark IDs @@ -41,4 +41,3 @@ Meteor.methods({ return apiIds; } }); - From e567f88ce8b76ee8d4061479f612da2cf20c3ff6 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:25:51 +0300 Subject: [PATCH 09/30] Move helpers; add setAverageRating helper --- apis/collection/helpers.js | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 apis/collection/helpers.js diff --git a/apis/collection/helpers.js b/apis/collection/helpers.js new file mode 100644 index 0000000000..01814dec13 --- /dev/null +++ b/apis/collection/helpers.js @@ -0,0 +1,97 @@ +import ss from 'simple-statistics'; + +ApiBackends.helpers({ + getAverageRating () { + console.log("getting average rating"); + // Fetch all ratings + var apiBackendRatings = ApiBackendRatings.find({ + apiBackendId: this._id + }).fetch(); + + // If ratings exist + if (apiBackendRatings) { + // Create array containing only rating values + var apiBackendRatingsArray = _.map(apiBackendRatings, function (rating) { + // get only the rating value; omit User ID and API Backend ID fields + return rating.rating; + }); + + // Get the average (mean) value for API Backend ratings + var apiBackendRatingsAverage = ss.mean(apiBackendRatingsArray); + + return apiBackendRatingsAverage; + } + }, + setAverageRating () { + // get average rating value + const averageRating = this.getAverageRating(); + + // Update the API Backend with average rating value + ApiBackends.update(this._id, {$set: {averageRating}}); + }, + getBookmarksCount () { + // Get API Backend ID + const apiBackendId = this._id; + + return ApiBookmarks.find({apiBackendId}).count(); + }, + getRating () { + // Get API Backend ID + const apiBackendId = this._id; + + // Get current user ID + const userId = Meteor.userId(); + + // Check if user is logged in + if (Meteor.userId()) { + // Check if user has rated API Backend + var userRating = ApiBackendRatings.findOne({ + apiBackendId, + userId + }); + + if (userRating) { + return userRating.rating; + } + } + + // Otherwise, get average rating + return this.averageRating; + }, + currentUserCanEdit () { + // Get current userId + var userId = Meteor.userId(); + + // Check that user is logged in + if( userId ) { + // Check if user is API manager + var isManager = _.contains(this.managerIds, userId); + + if (isManager) { + return true; + } + + // Check if user is administrator + var isAdmin = Roles.userIsInRole(userId, ['admin']); + + if (isAdmin) { + return true; + } + } else { + // User is not logged in + return false; + } + }, + currentUserIsManager () { + // Get current User ID + var userId = Meteor.userId(); + + // Get Manager IDs array from API Backend document + var managerIds = this.managerIds; + + // Check if User ID is in Manager IDs array + var isManager = _.contains(managerIds, userId); + + return isManager; + } +}); From 26ff894b63d1c0d37d997f1ebf8b5cff9de0c667 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:33:58 +0300 Subject: [PATCH 10/30] averageRating and bookmarkCount optional --- apis/collection/backend.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apis/collection/backend.js b/apis/collection/backend.js index 7d098c3c95..bf39d8a642 100644 --- a/apis/collection/backend.js +++ b/apis/collection/backend.js @@ -655,6 +655,7 @@ Schemas.ApiBackendsSchema = new SimpleSchema({ averageRating: { type: Number, decimal: true, + optional: true, autoform: { type: "hidden", label: false @@ -662,6 +663,7 @@ Schemas.ApiBackendsSchema = new SimpleSchema({ }, bookmarkCount: { type: Number, + optional: true, autoform: { type: "hidden", label: false From 7139fad723c79818a1d178551603ed29324b5e9b Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:46:00 +0300 Subject: [PATCH 11/30] Ensure apiRating value exists --- apis/collection/helpers.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/apis/collection/helpers.js b/apis/collection/helpers.js index 01814dec13..5bed99abfb 100644 --- a/apis/collection/helpers.js +++ b/apis/collection/helpers.js @@ -26,8 +26,11 @@ ApiBackends.helpers({ // get average rating value const averageRating = this.getAverageRating(); - // Update the API Backend with average rating value - ApiBackends.update(this._id, {$set: {averageRating}}); + // Check if average rating calculation succeeds + if (averageRating) { + // Update the API Backend with average rating value + ApiBackends.update(this._id, {$set: {averageRating}}); + } }, getBookmarksCount () { // Get API Backend ID From 644975028b8816e6de435e3254b1bdde663487cf Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 14:46:15 +0300 Subject: [PATCH 12/30] Add setAllApiBackendAverageRatings method --- apis/server/methods/ratings.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 apis/server/methods/ratings.js diff --git a/apis/server/methods/ratings.js b/apis/server/methods/ratings.js new file mode 100644 index 0000000000..f9ae31789a --- /dev/null +++ b/apis/server/methods/ratings.js @@ -0,0 +1,12 @@ +Meteor.methods({ + setAllApiBackendAverageRatings () { + // Get all API Backends + const apiBackends = ApiBackends.find().fetch(); + + // Update the average rating value for each API Backend + apiBackends.forEach(function (apiBackend) { + // Set average rating value for current API Backend + apiBackend.setAverageRating(); + }); + } +}); From e0072ebc6cd057fa2078a3ae9ea1fd5fd8bf9817 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:00:26 +0300 Subject: [PATCH 13/30] Include averageRating field --- catalogue/tabular.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/catalogue/tabular.js b/catalogue/tabular.js index 6a35b61b8b..e3ffed9d94 100644 --- a/catalogue/tabular.js +++ b/catalogue/tabular.js @@ -17,8 +17,9 @@ TabularTables.ApiTable = new Tabular.Table({ }, {tmpl: Meteor.isClient && Template.favourite, title: "Bookmark"}, { - tmpl: Meteor.isClient && Template.apiBackendRating, - title: "Rating" + data: "averageRating", + tmpl: Meteor.isClient && Template.apiBackendRating, + title: "Rating" } ], responsive: true, From cd089aed762cdbf65a93959ddba5c6b1c0dc20d1 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:01:05 +0300 Subject: [PATCH 14/30] Pre-populate averageRating star value --- ratings/client/rating.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ratings/client/rating.js b/ratings/client/rating.js index d4f0aeaf34..39551bd1a1 100644 --- a/ratings/client/rating.js +++ b/ratings/client/rating.js @@ -23,26 +23,29 @@ Template.apiBackendRating.rendered = function () { var instance = this; // Get API Backend ID from template instance - var apiBackend = instance.data; + var apiBackendId = instance.data._id; + + // get API Backend document + const apiBackend = ApiBackends.findOne(apiBackendId); instance.autorun(function () { // Make sure API Backend Rating subscription is ready if (instance.apiRatingSubscription.ready()) { // Check if user has previously rated API Backend var userRating = ApiBackendRatings.findOne({ - apiBackendId: apiBackend._id, + apiBackendId, userId: Meteor.userId() }); // Add the jQuery RateIt widget - $("#rating-" + apiBackend._id).rateit({ + $("#rating-" + apiBackendId).rateit({ max: 4, step: 1, resetable: false, // Only logged in user can rate readonly: Meteor.userId() ? false : true, // use previous rating, if exists - value: userRating ? userRating.rating : apiBackend.getRating() + value: userRating ? userRating.rating : apiBackend.averageRating }); } }); From a72f5d904fe6a0b226b638ea2d49b8a5e5dc8bf5 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:14:31 +0300 Subject: [PATCH 15/30] Add setBookmarkCount method; refactor to 'bookmark' --- apis/collection/helpers.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/apis/collection/helpers.js b/apis/collection/helpers.js index 5bed99abfb..623246286a 100644 --- a/apis/collection/helpers.js +++ b/apis/collection/helpers.js @@ -32,12 +32,22 @@ ApiBackends.helpers({ ApiBackends.update(this._id, {$set: {averageRating}}); } }, - getBookmarksCount () { + getBookmarkCount () { // Get API Backend ID const apiBackendId = this._id; return ApiBookmarks.find({apiBackendId}).count(); }, + setBookmarkCount () { + // get average rating value + const bookmarkCount = this.getBookmarkCount(); + + // Check if average rating calculation succeeds + if (bookmarkCount) { + // Update the API Backend with average rating value + ApiBackends.update(this._id, {$set: {bookmarkCount}}); + } + }, getRating () { // Get API Backend ID const apiBackendId = this._id; From 98271846d1e96fc50278b8121fde863deedef6c5 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:14:44 +0300 Subject: [PATCH 16/30] Add setAllApiBackendBookmarkCounts method --- apis/server/methods/bookmarks.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 apis/server/methods/bookmarks.js diff --git a/apis/server/methods/bookmarks.js b/apis/server/methods/bookmarks.js new file mode 100644 index 0000000000..b2161bff4c --- /dev/null +++ b/apis/server/methods/bookmarks.js @@ -0,0 +1,12 @@ +Meteor.methods({ + setAllApiBackendBookmarkCounts () { + // Get all API Backends + const apiBackends = ApiBackends.find().fetch(); + + // Update the average rating value for each API Backend + apiBackends.forEach(function (apiBackend) { + // Set average rating value for current API Backend + apiBackend.setBookmarkCount(); + }); + } +}); From 6731c73b90b9782b48ab33f58352acbbac2ac407 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:27:39 +0300 Subject: [PATCH 17/30] Comment and verbose variable name --- apis/collection/helpers.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apis/collection/helpers.js b/apis/collection/helpers.js index 623246286a..14de722e50 100644 --- a/apis/collection/helpers.js +++ b/apis/collection/helpers.js @@ -36,7 +36,10 @@ ApiBackends.helpers({ // Get API Backend ID const apiBackendId = this._id; - return ApiBookmarks.find({apiBackendId}).count(); + // Get count of API Bookmarks where API Backend ID is in API Backend IDs array + const apiBookmarkCount = ApiBookmarks.find({apiIds: apiBackendId}).count(); + + return apiBookmarkCount; }, setBookmarkCount () { // get average rating value From bfc8cff99a5ff13361b1db05ae1d985d24f534db Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:27:48 +0300 Subject: [PATCH 18/30] Add popularity column --- catalogue/tabular.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/catalogue/tabular.js b/catalogue/tabular.js index e3ffed9d94..1e9e767e4e 100644 --- a/catalogue/tabular.js +++ b/catalogue/tabular.js @@ -20,7 +20,8 @@ TabularTables.ApiTable = new Tabular.Table({ data: "averageRating", tmpl: Meteor.isClient && Template.apiBackendRating, title: "Rating" - } + }, + {data: "bookmarkCount", title: "Popularity"}, ], responsive: true, autoWidth: false From cfd9350dea09c435e542996790f77c37f5a442ed Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:32:26 +0300 Subject: [PATCH 19/30] Use object shorthand --- bookmarks/server/methods.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookmarks/server/methods.js b/bookmarks/server/methods.js index df9df65eea..730a62ee04 100644 --- a/bookmarks/server/methods.js +++ b/bookmarks/server/methods.js @@ -31,7 +31,7 @@ Meteor.methods({ } // Updating current user apiBookmarks - ApiBookmarks.update({userId: currentUserId},{$set: {apiIds: apiIds} }); + ApiBookmarks.update({userId: currentUserId},{$set: { apiIds } }); } else { // Insert bookmark to database From 0bb19fbea33432056c92a34f5cfd8e3515a62cd9 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:40:35 +0300 Subject: [PATCH 20/30] Unset bookmark count if no bookmarks --- apis/collection/helpers.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/apis/collection/helpers.js b/apis/collection/helpers.js index 14de722e50..908269cc82 100644 --- a/apis/collection/helpers.js +++ b/apis/collection/helpers.js @@ -49,6 +49,8 @@ ApiBackends.helpers({ if (bookmarkCount) { // Update the API Backend with average rating value ApiBackends.update(this._id, {$set: {bookmarkCount}}); + } else { + ApiBackends.update(this._id, {$unset: {bookmarkCount: ""}}) } }, getRating () { From 7e1d0ccc56793d7280e7960cbbfcffd6e0d27e99 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:40:52 +0300 Subject: [PATCH 21/30] Add setApiBackendBookmarkCount method --- apis/server/methods/bookmarks.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apis/server/methods/bookmarks.js b/apis/server/methods/bookmarks.js index b2161bff4c..bf10dfa194 100644 --- a/apis/server/methods/bookmarks.js +++ b/apis/server/methods/bookmarks.js @@ -8,5 +8,13 @@ Meteor.methods({ // Set average rating value for current API Backend apiBackend.setBookmarkCount(); }); + }, + setApiBackendBookmarkCount (apiBackendId) { + console.log("Setting api bookmark count") + // Get API Backend + const apiBackend = ApiBackends.findOne(apiBackendId); + + // Update the API Backend bookmark count + apiBackend.setBookmarkCount(); } }); From 90bd6aeca7257cd4c462066f2cda5c24a6ee9791 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:41:06 +0300 Subject: [PATCH 22/30] Call setApiBackendBookmarkCount method --- bookmarks/server/methods.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bookmarks/server/methods.js b/bookmarks/server/methods.js index 730a62ee04..56f67a0cfc 100644 --- a/bookmarks/server/methods.js +++ b/bookmarks/server/methods.js @@ -38,6 +38,9 @@ Meteor.methods({ ApiBookmarks.insert(userBookmarks); } + // Update the API Backend bookmark count + Meteor.call("setApiBackendBookmarkCount", backendId); + return apiIds; } }); From 16dc998dbf05423db6c4297e4bd88da02492132d Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:45:38 +0300 Subject: [PATCH 23/30] Add setApiBackendAverageRating method --- apis/server/methods/ratings.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apis/server/methods/ratings.js b/apis/server/methods/ratings.js index f9ae31789a..f05baae978 100644 --- a/apis/server/methods/ratings.js +++ b/apis/server/methods/ratings.js @@ -8,5 +8,13 @@ Meteor.methods({ // Set average rating value for current API Backend apiBackend.setAverageRating(); }); + }, + setApiBackendAverageRating (apiBackendId) { + console.log("Setting api bookmark count") + // Get API Backend + const apiBackend = ApiBackends.findOne(apiBackendId); + + // Update the API Backend bookmark count + apiBackend.setAverageRating(); } }); From 16f2543a8c17f239200c41a8cf4dae516b376716 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Mon, 13 Jun 2016 15:45:48 +0300 Subject: [PATCH 24/30] Call setApiBackendAverageRating method --- ratings/client/rating.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ratings/client/rating.js b/ratings/client/rating.js index 39551bd1a1..7b2acd8bdd 100644 --- a/ratings/client/rating.js +++ b/ratings/client/rating.js @@ -94,6 +94,9 @@ Template.apiBackendRating.events({ // Otherwise, create a new rating ApiBackendRatings.insert(apiBackendRating); } + + // Update the API Backend average rating + Meteor.call("setApiBackendAverageRating", apiBackendId); } }); From cad5453831eab1feaef7240675e5715823523f5a Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Tue, 14 Jun 2016 15:41:00 +0300 Subject: [PATCH 25/30] Cleanup console.log --- apis/server/methods/ratings.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apis/server/methods/ratings.js b/apis/server/methods/ratings.js index f05baae978..c33df1a8a9 100644 --- a/apis/server/methods/ratings.js +++ b/apis/server/methods/ratings.js @@ -10,7 +10,6 @@ Meteor.methods({ }); }, setApiBackendAverageRating (apiBackendId) { - console.log("Setting api bookmark count") // Get API Backend const apiBackend = ApiBackends.findOne(apiBackendId); From a2f52f25dbe6e44b3dff16e59701cba991b8cf7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Jyrkk=C3=A4?= Date: Tue, 14 Jun 2016 16:46:40 +0300 Subject: [PATCH 26/30] add migration --- server/migrations.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/migrations.js b/server/migrations.js index 58470db0dc..ed0db7060a 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -19,3 +19,12 @@ Migrations.add({ }); } }); + +Migrations.add({ + version: 2, + name: 'Set API backend bookmarkCount & averageRating fields', + up: function() { + Meteor.call('setAllApiBackendBookmarkCounts'); + Meteor.call('setAllApiBackendAverageRatings'); + } +}); From a51e66d0f4a21a3de917fcc03e7795a3d281ddf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Jyrkk=C3=A4?= Date: Tue, 14 Jun 2016 16:47:55 +0300 Subject: [PATCH 27/30] Remove console.log --- apis/collection/helpers.js | 1 - 1 file changed, 1 deletion(-) diff --git a/apis/collection/helpers.js b/apis/collection/helpers.js index 908269cc82..3bf2630fe1 100644 --- a/apis/collection/helpers.js +++ b/apis/collection/helpers.js @@ -2,7 +2,6 @@ import ss from 'simple-statistics'; ApiBackends.helpers({ getAverageRating () { - console.log("getting average rating"); // Fetch all ratings var apiBackendRatings = ApiBackendRatings.find({ apiBackendId: this._id From d49e8f4fc471196b0a4c641e363077d07d30e1bf Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Wed, 15 Jun 2016 11:43:17 +0300 Subject: [PATCH 28/30] Remove bookmarkCount and averageRating migration --- server/migrations.js | 9 --------- 1 file changed, 9 deletions(-) diff --git a/server/migrations.js b/server/migrations.js index ed0db7060a..58470db0dc 100644 --- a/server/migrations.js +++ b/server/migrations.js @@ -19,12 +19,3 @@ Migrations.add({ }); } }); - -Migrations.add({ - version: 2, - name: 'Set API backend bookmarkCount & averageRating fields', - up: function() { - Meteor.call('setAllApiBackendBookmarkCounts'); - Meteor.call('setAllApiBackendAverageRatings'); - } -}); From da38c73e7c2d48586ecdc63b8d10944fa4b53a83 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Wed, 15 Jun 2016 11:44:30 +0300 Subject: [PATCH 29/30] Set bookmarkCounts and averageRatings on startup --- apis/server/startup.js | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 apis/server/startup.js diff --git a/apis/server/startup.js b/apis/server/startup.js new file mode 100644 index 0000000000..1f15cd9e2e --- /dev/null +++ b/apis/server/startup.js @@ -0,0 +1,7 @@ +Meteor.startup(function () { + // Make sure all API backends have bookmark counts + Meteor.call('setAllApiBackendBookmarkCounts'); + + // Make sure all API backends have average ratings + Meteor.call('setAllApiBackendAverageRatings'); +}); From d1b98d91479b6dd66edebbace09458dddcde8456 Mon Sep 17 00:00:00 2001 From: Brylie Christopher Oxley Date: Wed, 15 Jun 2016 11:46:29 +0300 Subject: [PATCH 30/30] Remove console.log --- apis/server/methods/bookmarks.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apis/server/methods/bookmarks.js b/apis/server/methods/bookmarks.js index bf10dfa194..dadd5799e7 100644 --- a/apis/server/methods/bookmarks.js +++ b/apis/server/methods/bookmarks.js @@ -10,10 +10,9 @@ Meteor.methods({ }); }, setApiBackendBookmarkCount (apiBackendId) { - console.log("Setting api bookmark count") // Get API Backend const apiBackend = ApiBackends.findOne(apiBackendId); - + // Update the API Backend bookmark count apiBackend.setBookmarkCount(); }