veltrixcode commited on
Commit
566a8f7
·
verified ·
1 Parent(s): 312d1e9

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +21 -4
server.js CHANGED
@@ -412,7 +412,13 @@ app.get('/api/user-submissions/:userId', checkOtpAuth, async (req, res) => {
412
  'SELECT * FROM submissions WHERE user_id = $1 ORDER BY created_at DESC',
413
  [userId]
414
  );
415
- res.json({ success: true, submissions: result.rows });
 
 
 
 
 
 
416
  } catch (error) {
417
  res.status(500).json({ success: false, error: 'Failed to fetch submissions' });
418
  }
@@ -639,7 +645,13 @@ app.get('/api/admin/submissions', async (req, res) => {
639
  JOIN users u ON s.user_id = u.id
640
  ORDER BY s.created_at DESC
641
  `);
642
- res.json({ success: true, submissions: result.rows });
 
 
 
 
 
 
643
  } catch (error) {
644
  console.error('Error fetching submissions:', error);
645
  res.status(500).json({ success: false, error: 'Failed to fetch submissions' });
@@ -720,8 +732,13 @@ app.get('/api/admin/submissions/:submissionId', async (req, res) => {
720
  if (result.rows.length === 0) {
721
  return res.status(404).json({ success: false, error: 'Submission not found' });
722
  }
723
-
724
- res.json({ success: true, submission: result.rows[0] });
 
 
 
 
 
725
  } catch (error) {
726
  console.error('Error fetching submission details:', error);
727
  res.status(500).json({ success: false, error: 'Failed to fetch submission details' });
 
412
  'SELECT * FROM submissions WHERE user_id = $1 ORDER BY created_at DESC',
413
  [userId]
414
  );
415
+ // Ensure card_type and payment_method are always present
416
+ const submissions = result.rows.map(sub => ({
417
+ ...sub,
418
+ card_type: sub.card_type || 'oldsub',
419
+ payment_method: sub.payment_method || 'oldsub'
420
+ }));
421
+ res.json({ success: true, submissions });
422
  } catch (error) {
423
  res.status(500).json({ success: false, error: 'Failed to fetch submissions' });
424
  }
 
645
  JOIN users u ON s.user_id = u.id
646
  ORDER BY s.created_at DESC
647
  `);
648
+ // Ensure card_type and payment_method are always present
649
+ const submissions = result.rows.map(sub => ({
650
+ ...sub,
651
+ card_type: sub.card_type || 'oldsub',
652
+ payment_method: sub.payment_method || 'oldsub'
653
+ }));
654
+ res.json({ success: true, submissions });
655
  } catch (error) {
656
  console.error('Error fetching submissions:', error);
657
  res.status(500).json({ success: false, error: 'Failed to fetch submissions' });
 
732
  if (result.rows.length === 0) {
733
  return res.status(404).json({ success: false, error: 'Submission not found' });
734
  }
735
+ // Ensure card_type and payment_method are always present
736
+ const submission = {
737
+ ...result.rows[0],
738
+ card_type: result.rows[0].card_type || 'oldsub',
739
+ payment_method: result.rows[0].payment_method || 'oldsub'
740
+ };
741
+ res.json({ success: true, submission });
742
  } catch (error) {
743
  console.error('Error fetching submission details:', error);
744
  res.status(500).json({ success: false, error: 'Failed to fetch submission details' });