bulltrackers-module 1.0.607 → 1.0.609

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1409,25 +1409,52 @@ const fetchAllReviewsForPI = async (db, piId, limit = 100) => {
1409
1409
  .limit(parseInt(limit))
1410
1410
  .get();
1411
1411
 
1412
- const reviews = snap.docs.map(doc => doc.data());
1412
+ // Convert Firestore timestamps to ISO strings for frontend
1413
+ const reviews = snap.docs.map(doc => {
1414
+ const data = doc.data();
1415
+ // Convert Firestore timestamps to ISO strings
1416
+ if (data.createdAt) {
1417
+ data.createdAt = data.createdAt.toDate ? data.createdAt.toDate().toISOString() :
1418
+ (data.createdAt.toISOString ? data.createdAt.toISOString() :
1419
+ (data.createdAt._seconds ? new Date(data.createdAt._seconds * 1000).toISOString() : data.createdAt));
1420
+ }
1421
+ if (data.updatedAt) {
1422
+ data.updatedAt = data.updatedAt.toDate ? data.updatedAt.toDate().toISOString() :
1423
+ (data.updatedAt.toISOString ? data.updatedAt.toISOString() :
1424
+ (data.updatedAt._seconds ? new Date(data.updatedAt._seconds * 1000).toISOString() : data.updatedAt));
1425
+ }
1426
+ return data;
1427
+ });
1413
1428
 
1414
1429
  // 2. Calculate Stats
1415
1430
  let total = 0;
1416
- const distribution = { 1:0, 2:0, 3:0, 4:0, 5:0 };
1431
+ const counts = { 1: 0, 2: 0, 3: 0, 4: 0, 5: 0 };
1417
1432
 
1418
1433
  reviews.forEach(r => {
1419
1434
  const rating = r.rating || 0;
1420
1435
  total += rating;
1421
- if(distribution[rating] !== undefined) distribution[rating]++;
1436
+ if(counts[rating] !== undefined) counts[rating]++;
1422
1437
  });
1423
1438
 
1424
1439
  const count = reviews.length;
1425
- const avg = count > 0 ? (total / count).toFixed(2) : 0;
1440
+ const avg = count > 0 ? Number((total / count).toFixed(2)) : 0;
1441
+
1442
+ // Calculate percentages
1443
+ const percentages = {
1444
+ 1: count > 0 ? Number((counts[1] / count * 100).toFixed(1)) : 0,
1445
+ 2: count > 0 ? Number((counts[2] / count * 100).toFixed(1)) : 0,
1446
+ 3: count > 0 ? Number((counts[3] / count * 100).toFixed(1)) : 0,
1447
+ 4: count > 0 ? Number((counts[4] / count * 100).toFixed(1)) : 0,
1448
+ 5: count > 0 ? Number((counts[5] / count * 100).toFixed(1)) : 0
1449
+ };
1426
1450
 
1427
1451
  return {
1428
1452
  count,
1429
1453
  averageRating: avg,
1430
- distribution,
1454
+ ratingDistribution: {
1455
+ counts,
1456
+ percentages
1457
+ },
1431
1458
  reviews
1432
1459
  };
1433
1460
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bulltrackers-module",
3
- "version": "1.0.607",
3
+ "version": "1.0.609",
4
4
  "description": "Helper Functions for Bulltrackers.",
5
5
  "main": "index.js",
6
6
  "files": [