Skip to content

Commit b55a70b

Browse files
committed
final comments
1 parent d84333b commit b55a70b

File tree

2 files changed

+36
-43
lines changed

2 files changed

+36
-43
lines changed

components/trustpilot/sources/common/polling.mjs

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -74,55 +74,50 @@ export default {
7474
},
7575
},
7676
async run({ $ }) {
77-
try {
78-
// Get the last review time for filtering new reviews
79-
const lastReviewTime = this._getLastReviewTime();
77+
// Get the last review time for filtering new reviews
78+
const lastReviewTime = this._getLastReviewTime();
8079

81-
// Get fetch parameters from child class
82-
const fetchParams = this.getFetchParams(lastReviewTime);
80+
// Get fetch parameters from child class
81+
const fetchParams = this.getFetchParams(lastReviewTime);
8382

84-
// Fetch reviews using child class method
85-
const result = await this.fetchReviews($, fetchParams);
86-
const reviews = result.reviews || [];
83+
// Fetch reviews using child class method
84+
const result = await this.fetchReviews($, fetchParams);
85+
const reviews = result.reviews || [];
8786

88-
if (!reviews.length) {
89-
console.log("No reviews found");
90-
return;
91-
}
87+
if (!reviews.length) {
88+
console.log("No reviews found");
89+
return;
90+
}
9291

93-
// Filter for new reviews (child class may override)
94-
const newReviews = this.filterNewReviews(reviews, lastReviewTime);
92+
// Filter for new reviews (child class may override)
93+
const newReviews = this.filterNewReviews(reviews, lastReviewTime);
9594

96-
if (!newReviews.length) {
97-
console.log("No new reviews since last poll");
98-
return;
99-
}
100-
101-
// Track the latest review time
102-
let latestReviewTime = lastReviewTime;
95+
if (!newReviews.length) {
96+
console.log("No new reviews since last poll");
97+
return;
98+
}
10399

104-
for (const review of newReviews) {
105-
// Track the latest review time
106-
const reviewTime = new Date(review.createdAt).toISOString();
107-
if (!latestReviewTime || new Date(reviewTime) > new Date(latestReviewTime)) {
108-
latestReviewTime = reviewTime;
109-
}
100+
// Track the latest review time
101+
let latestReviewTime = lastReviewTime;
110102

111-
// Emit the review with unique ID and summary
112-
this.$emit(review, {
113-
id: review.id,
114-
summary: this.generateSummary(review),
115-
ts: new Date(review.createdAt).getTime(),
116-
});
103+
for (const review of newReviews) {
104+
// Track the latest review time
105+
const reviewTime = new Date(review.createdAt).toISOString();
106+
if (!latestReviewTime || new Date(reviewTime) > new Date(latestReviewTime)) {
107+
latestReviewTime = reviewTime;
117108
}
118109

119-
// Update the last review time for next poll
120-
if (latestReviewTime && latestReviewTime !== lastReviewTime) {
121-
this._setLastReviewTime(latestReviewTime);
122-
}
110+
// Emit the review with unique ID and summary
111+
this.$emit(review, {
112+
id: review.id,
113+
summary: this.generateSummary(review),
114+
ts: new Date(review.createdAt).getTime(),
115+
});
116+
}
123117

124-
} catch (error) {
125-
throw new Error(`Failed to fetch reviews: ${error.message}`);
118+
// Update the last review time for next poll
119+
if (latestReviewTime && latestReviewTime !== lastReviewTime) {
120+
this._setLastReviewTime(latestReviewTime);
126121
}
127122
},
128123
};

components/trustpilot/trustpilot.app.mjs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,10 @@ export default {
221221
// Handle the correct response structure (productReviews, not reviews)
222222
const reviews = response.productReviews?.map(parseProductReview) || [];
223223
const pagination = {
224-
total: response.links?.total || 0,
224+
total: response.total || 0,
225225
page: queryParams.page || 1,
226226
perPage: queryParams.perPage || 20,
227-
hasMore: response.links?.next
228-
? true
229-
: false,
227+
hasMore: response.links?.some((l) => l.rel === "next") || false,
230228
};
231229

232230
return {

0 commit comments

Comments
 (0)