veltrixcode commited on
Commit
33094e5
·
verified ·
1 Parent(s): 1195ada

Update server.js

Browse files
Files changed (1) hide show
  1. server.js +32 -16
server.js CHANGED
@@ -412,12 +412,18 @@ 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
- // 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' });
@@ -645,12 +651,18 @@ app.get('/api/admin/submissions', async (req, res) => {
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);
@@ -732,12 +744,16 @@ app.get('/api/admin/submissions/:submissionId', async (req, res) => {
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);
 
412
  'SELECT * FROM submissions WHERE user_id = $1 ORDER BY created_at DESC',
413
  [userId]
414
  );
415
+ // Ensure card_type, payment_method, and payment_address are always present, and remove upi_id
416
+ const submissions = result.rows.map(sub => {
417
+ const payment_address = sub.payment_address || sub.upi_id || 'oldsub';
418
+ const mapped = {
419
+ ...sub,
420
+ payment_address,
421
+ card_type: sub.card_type || 'oldsub',
422
+ payment_method: sub.payment_method || 'oldsub'
423
+ };
424
+ delete mapped.upi_id;
425
+ return mapped;
426
+ });
427
  res.json({ success: true, submissions });
428
  } catch (error) {
429
  res.status(500).json({ success: false, error: 'Failed to fetch submissions' });
 
651
  JOIN users u ON s.user_id = u.id
652
  ORDER BY s.created_at DESC
653
  `);
654
+ // Ensure card_type, payment_method, and payment_address are always present, and remove upi_id
655
+ const submissions = result.rows.map(sub => {
656
+ const payment_address = sub.payment_address || sub.upi_id || 'oldsub';
657
+ const mapped = {
658
+ ...sub,
659
+ payment_address,
660
+ card_type: sub.card_type || 'oldsub',
661
+ payment_method: sub.payment_method || 'oldsub'
662
+ };
663
+ delete mapped.upi_id;
664
+ return mapped;
665
+ });
666
  res.json({ success: true, submissions });
667
  } catch (error) {
668
  console.error('Error fetching submissions:', error);
 
744
  if (result.rows.length === 0) {
745
  return res.status(404).json({ success: false, error: 'Submission not found' });
746
  }
747
+ // Ensure card_type, payment_method, and payment_address are always present, and remove upi_id
748
+ const sub = result.rows[0];
749
+ const payment_address = sub.payment_address || sub.upi_id || 'oldsub';
750
  const submission = {
751
+ ...sub,
752
+ payment_address,
753
+ card_type: sub.card_type || 'oldsub',
754
+ payment_method: sub.payment_method || 'oldsub'
755
  };
756
+ delete submission.upi_id;
757
  res.json({ success: true, submission });
758
  } catch (error) {
759
  console.error('Error fetching submission details:', error);