Skip to content

Commit 4bcfefb

Browse files
committed
Merge branch 'staging' of github.com:UNICEFECAR/USupport-cms
2 parents d246c90 + ae4a2a7 commit 4bcfefb

1 file changed

Lines changed: 33 additions & 21 deletions

File tree

src/api/category/controllers/category.js

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,17 @@ module.exports = createCoreController(
148148

149149
// Add engagement metrics from engagements data
150150
allArticles = allArticles.map((article) => {
151-
const metrics = contentMetrics.get(`article_${article.id}`) || {
152-
likes: 0,
153-
dislikes: 0,
154-
views: 0,
155-
downloads: 0,
156-
shares: 0,
157-
};
151+
const originalMetrics = contentMetrics.get(`article_${article.id}`);
152+
// Create a copy to avoid mutating the original Map object
153+
const metrics = originalMetrics
154+
? { ...originalMetrics }
155+
: {
156+
likes: 0,
157+
dislikes: 0,
158+
views: 0,
159+
downloads: 0,
160+
shares: 0,
161+
};
158162
if (shouldAddLegacyViews) {
159163
metrics.views += parseInt(article.read_count || 0);
160164
}
@@ -181,13 +185,17 @@ module.exports = createCoreController(
181185

182186
// Add engagement metrics from engagements data
183187
allVideos = allVideos.map((video) => {
184-
const metrics = contentMetrics.get(`video_${video.id}`) || {
185-
likes: 0,
186-
dislikes: 0,
187-
views: 0,
188-
downloads: 0,
189-
shares: 0,
190-
};
188+
const originalMetrics = contentMetrics.get(`video_${video.id}`);
189+
// Create a copy to avoid mutating the original Map object
190+
const metrics = originalMetrics
191+
? { ...originalMetrics }
192+
: {
193+
likes: 0,
194+
dislikes: 0,
195+
views: 0,
196+
downloads: 0,
197+
shares: 0,
198+
};
191199
if (shouldAddLegacyViews) {
192200
metrics.views += parseInt(video.view_count || 0);
193201
}
@@ -213,13 +221,17 @@ module.exports = createCoreController(
213221

214222
// Add engagement metrics from engagements data
215223
allPodcasts = allPodcasts.map((podcast) => {
216-
const metrics = contentMetrics.get(`podcast_${podcast.id}`) || {
217-
likes: 0,
218-
dislikes: 0,
219-
views: 0,
220-
downloads: 0,
221-
shares: 0,
222-
};
224+
const originalMetrics = contentMetrics.get(`podcast_${podcast.id}`);
225+
// Create a copy to avoid mutating the original Map object
226+
const metrics = originalMetrics
227+
? { ...originalMetrics }
228+
: {
229+
likes: 0,
230+
dislikes: 0,
231+
views: 0,
232+
downloads: 0,
233+
shares: 0,
234+
};
223235
if (shouldAddLegacyViews) {
224236
metrics.views += parseInt(podcast.view_count || 0);
225237
}

0 commit comments

Comments
 (0)