Tristan Yu commited on
Commit
8cbe47a
·
1 Parent(s): c5255ae

Remove duplicate routes and fix validation to allow image-only content

Browse files
client/src/pages/TutorialTasks.tsx CHANGED
@@ -666,7 +666,8 @@ const TutorialTasks: React.FC = () => {
666
  return;
667
  }
668
 
669
- if (!editForm.content.trim()) {
 
670
  return;
671
  }
672
 
 
666
  return;
667
  }
668
 
669
+ // Allow either content or imageUrl, but not both empty
670
+ if (!editForm.content.trim() && !editForm.imageUrl.trim()) {
671
  return;
672
  }
673
 
server/routes/auth.js CHANGED
@@ -355,43 +355,7 @@ router.get('/admin/tutorial-tasks', authenticateToken, async (req, res) => {
355
  }
356
  });
357
 
358
- // Add new tutorial task (admin only)
359
- router.post('/admin/tutorial-tasks', authenticateToken, async (req, res) => {
360
- try {
361
- const SourceText = require('../models/SourceText');
362
- const { title, content, sourceLanguage, sourceCulture, weekNumber, difficulty, culturalElements, imageUrl, imageAlt, translationBrief } = req.body;
363
-
364
- // Validate required fields
365
- if (!title || !content || !sourceLanguage || !weekNumber) {
366
- return res.status(400).json({ error: 'Title, content, sourceLanguage, and weekNumber are required' });
367
- }
368
-
369
- const newTutorialTask = new SourceText({
370
- title,
371
- content,
372
- sourceLanguage,
373
- category: 'tutorial',
374
- weekNumber: parseInt(weekNumber),
375
- difficulty: difficulty || 'intermediate',
376
- culturalElements: culturalElements || [],
377
- sourceType: 'tutorial',
378
- imageUrl,
379
- imageAlt,
380
- translationBrief
381
- });
382
-
383
- const savedTask = await newTutorialTask.save();
384
-
385
- res.status(201).json({
386
- success: true,
387
- message: 'Tutorial task added successfully',
388
- tutorialTask: savedTask
389
- });
390
- } catch (error) {
391
- console.error('Add tutorial task error:', error);
392
- res.status(500).json({ error: 'Failed to add tutorial task' });
393
- }
394
- });
395
 
396
  // Update tutorial task (admin only)
397
  router.put('/admin/tutorial-tasks/:id', authenticateToken, requireAdmin, async (req, res) => {
@@ -471,48 +435,7 @@ router.get('/admin/weekly-practice', authenticateToken, async (req, res) => {
471
  }
472
  });
473
 
474
- // Add new weekly practice task (admin only)
475
- router.post('/admin/weekly-practice', authenticateToken, async (req, res) => {
476
- try {
477
- const SourceText = require('../models/SourceText');
478
- const { title, content, sourceLanguage, sourceCulture, weekNumber, difficulty, culturalElements } = req.body;
479
-
480
- // Validate required fields - allow either content or imageUrl
481
- if (!title || !sourceLanguage || !weekNumber) {
482
- return res.status(400).json({ error: 'Title, sourceLanguage, and weekNumber are required' });
483
- }
484
-
485
- if (!content && !req.body.imageUrl) {
486
- return res.status(400).json({ error: 'Either content or imageUrl is required' });
487
- }
488
-
489
- const newWeeklyPractice = new SourceText({
490
- title,
491
- content: content || (req.body.imageUrl ? 'Image-based practice' : ''),
492
- sourceLanguage,
493
- category: 'weekly-practice',
494
- weekNumber: parseInt(weekNumber),
495
- difficulty: difficulty || 'intermediate',
496
- culturalElements: culturalElements || [],
497
- sourceType: 'weekly-practice',
498
- imageUrl: req.body.imageUrl || null,
499
- imageAlt: req.body.imageAlt || null,
500
- imageSize: req.body.imageSize || 200,
501
- imageAlignment: req.body.imageAlignment || 'center'
502
- });
503
-
504
- const savedPractice = await newWeeklyPractice.save();
505
-
506
- res.status(201).json({
507
- success: true,
508
- message: 'Weekly practice added successfully',
509
- weeklyPractice: savedPractice
510
- });
511
- } catch (error) {
512
- console.error('Add weekly practice error:', error);
513
- res.status(500).json({ error: 'Failed to add weekly practice' });
514
- }
515
- });
516
 
517
  // Create weekly practice task (admin only)
518
  router.post('/admin/weekly-practice', authenticateToken, requireAdmin, async (req, res) => {
 
355
  }
356
  });
357
 
358
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
359
 
360
  // Update tutorial task (admin only)
361
  router.put('/admin/tutorial-tasks/:id', authenticateToken, requireAdmin, async (req, res) => {
 
435
  }
436
  });
437
 
438
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
439
 
440
  // Create weekly practice task (admin only)
441
  router.post('/admin/weekly-practice', authenticateToken, requireAdmin, async (req, res) => {