-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-products.js
More file actions
56 lines (45 loc) · 1.69 KB
/
debug-products.js
File metadata and controls
56 lines (45 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
const https = require('https');
const url = "https://ecombackend-vl7q.onrender.com/getAllProducts";
console.log(`Fetching products from ${url}...`);
https.get(url, (res) => {
let data = '';
res.on('data', (chunk) => {
data += chunk;
});
res.on('end', () => {
try {
const json = JSON.parse(data);
if (json.success && json.data) {
console.log(`✅ Success! Fetched ${json.data.length} products.\n`);
// Analyze first product
if (json.data.length > 0) {
console.log("--- First Product Structure ---");
console.log(JSON.stringify(json.data[0], null, 2));
console.log("-------------------------------\n");
}
// Analyze Categories
const categories = {};
json.data.forEach(p => {
const cat = p.category ? p.category : "(undefined)";
categories[cat] = (categories[cat] || 0) + 1;
});
console.log("--- Unique Categories Found ---");
console.table(categories);
// Check "Men" Logic
const menMatches = json.data.filter(item =>
item.category?.toLowerCase() === "men" ||
item.category?.toLowerCase() === "male" ||
item.category?.toLowerCase() === "man"
);
console.log(`\nLocal Logic Check: Found ${menMatches.length} items that match 'men', 'male', or 'man'.`);
} else {
console.log("❌ API returned success=false or no data:", json);
}
} catch (e) {
console.error("❌ Failed to parse JSON:", e.message);
console.log("Raw Data Preview:", data.substring(0, 200));
}
});
}).on('error', (e) => {
console.error("❌ Network Error:", e);
});