Spaces:
Sleeping
Sleeping
Tristan Yu commited on
Commit ·
7f79405
1
Parent(s): a4e6f0a
Add debug logging to weekly practice endpoint
Browse files- routes/sourceTexts.js +15 -1
routes/sourceTexts.js
CHANGED
|
@@ -247,17 +247,31 @@ router.get('/weekly-practice/week/:weekNumber', async (req, res) => {
|
|
| 247 |
return res.status(400).json({ error: 'Invalid week number. Must be between 1 and 6.' });
|
| 248 |
}
|
| 249 |
|
|
|
|
|
|
|
|
|
|
| 250 |
const practices = await SourceText.find({
|
| 251 |
category: 'weekly-practice',
|
| 252 |
weekNumber: weekNumber,
|
| 253 |
isActive: true
|
| 254 |
}).sort({ createdAt: 1 });
|
| 255 |
|
|
|
|
|
|
|
| 256 |
if (practices.length === 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 257 |
return res.status(404).json({
|
| 258 |
error: `No weekly practice found for week ${weekNumber}`,
|
| 259 |
practices: [],
|
| 260 |
-
weekNumber: weekNumber
|
|
|
|
|
|
|
|
|
|
|
|
|
| 261 |
});
|
| 262 |
}
|
| 263 |
|
|
|
|
| 247 |
return res.status(400).json({ error: 'Invalid week number. Must be between 1 and 6.' });
|
| 248 |
}
|
| 249 |
|
| 250 |
+
// Debug: Log what we're searching for
|
| 251 |
+
console.log(`Searching for weekly practice week ${weekNumber}`);
|
| 252 |
+
|
| 253 |
const practices = await SourceText.find({
|
| 254 |
category: 'weekly-practice',
|
| 255 |
weekNumber: weekNumber,
|
| 256 |
isActive: true
|
| 257 |
}).sort({ createdAt: 1 });
|
| 258 |
|
| 259 |
+
console.log(`Found ${practices.length} practices for week ${weekNumber}`);
|
| 260 |
+
|
| 261 |
if (practices.length === 0) {
|
| 262 |
+
// Debug: Check what's actually in the database
|
| 263 |
+
const allTexts = await SourceText.find({});
|
| 264 |
+
console.log(`Total texts in database: ${allTexts.length}`);
|
| 265 |
+
console.log('Sample texts:', allTexts.slice(0, 3).map(t => ({ title: t.title, category: t.category, weekNumber: t.weekNumber })));
|
| 266 |
+
|
| 267 |
return res.status(404).json({
|
| 268 |
error: `No weekly practice found for week ${weekNumber}`,
|
| 269 |
practices: [],
|
| 270 |
+
weekNumber: weekNumber,
|
| 271 |
+
debug: {
|
| 272 |
+
totalTexts: allTexts.length,
|
| 273 |
+
sampleTexts: allTexts.slice(0, 3).map(t => ({ title: t.title, category: t.category, weekNumber: t.weekNumber }))
|
| 274 |
+
}
|
| 275 |
});
|
| 276 |
}
|
| 277 |
|