Spaces:
Paused
Paused
Update server.js
Browse files
server.js
CHANGED
|
@@ -4,7 +4,6 @@ const cors = require('cors');
|
|
| 4 |
const path = require('path');
|
| 5 |
const bcrypt = require('bcrypt');
|
| 6 |
const multer = require('multer');
|
| 7 |
-
const { generateOtp, sendOtpEmail } = require('./mailService');
|
| 8 |
const { getPool, initializeDatabase, closePool } = require('./db');
|
| 9 |
const otpService = require('./otpService');
|
| 10 |
const axios = require('axios');
|
|
@@ -428,17 +427,19 @@ app.post('/api/gift-cards', checkOtpAuth, async (req, res) => {
|
|
| 428 |
ticket_number,
|
| 429 |
upi_id,
|
| 430 |
amount,
|
| 431 |
-
proof_video_url
|
|
|
|
|
|
|
| 432 |
} = req.body;
|
| 433 |
const userId = req.headers['x-user-id'];
|
| 434 |
|
| 435 |
// Generate ticket number if not provided
|
| 436 |
const finalTicketNumber = ticket_number || `TKT-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
| 437 |
|
| 438 |
-
if (!ticket_user_name || !gc_code || !gc_phone || !upi_id || !amount || !proof_video_url) {
|
| 439 |
return res.status(400).json({
|
| 440 |
success: false,
|
| 441 |
-
error: 'All fields are required including the video URL'
|
| 442 |
});
|
| 443 |
}
|
| 444 |
|
|
@@ -452,9 +453,11 @@ app.post('/api/gift-cards', checkOtpAuth, async (req, res) => {
|
|
| 452 |
ticket_number,
|
| 453 |
upi_id,
|
| 454 |
amount,
|
| 455 |
-
proof_video_url
|
| 456 |
-
|
| 457 |
-
|
|
|
|
|
|
|
| 458 |
);
|
| 459 |
res.json({
|
| 460 |
success: true,
|
|
@@ -725,6 +728,26 @@ app.get('/api/admin/submissions/:submissionId', async (req, res) => {
|
|
| 725 |
}
|
| 726 |
});
|
| 727 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 728 |
// Check if submission is open (Sunday 9am-9pm)
|
| 729 |
app.get('/isubmissionopen', (req, res) => {
|
| 730 |
const now = new Date();
|
|
|
|
| 4 |
const path = require('path');
|
| 5 |
const bcrypt = require('bcrypt');
|
| 6 |
const multer = require('multer');
|
|
|
|
| 7 |
const { getPool, initializeDatabase, closePool } = require('./db');
|
| 8 |
const otpService = require('./otpService');
|
| 9 |
const axios = require('axios');
|
|
|
|
| 427 |
ticket_number,
|
| 428 |
upi_id,
|
| 429 |
amount,
|
| 430 |
+
proof_video_url,
|
| 431 |
+
card_type, // new field
|
| 432 |
+
payment_method // new field
|
| 433 |
} = req.body;
|
| 434 |
const userId = req.headers['x-user-id'];
|
| 435 |
|
| 436 |
// Generate ticket number if not provided
|
| 437 |
const finalTicketNumber = ticket_number || `TKT-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`;
|
| 438 |
|
| 439 |
+
if (!ticket_user_name || !gc_code || !gc_phone || !upi_id || !amount || !proof_video_url || !card_type || !payment_method) {
|
| 440 |
return res.status(400).json({
|
| 441 |
success: false,
|
| 442 |
+
error: 'All fields are required including the video URL, card type, and payment method'
|
| 443 |
});
|
| 444 |
}
|
| 445 |
|
|
|
|
| 453 |
ticket_number,
|
| 454 |
upi_id,
|
| 455 |
amount,
|
| 456 |
+
proof_video_url,
|
| 457 |
+
card_type,
|
| 458 |
+
payment_method
|
| 459 |
+
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id`,
|
| 460 |
+
[userId, ticket_user_name, gc_code, gc_phone, finalTicketNumber, upi_id, amount, proof_video_url, card_type, payment_method]
|
| 461 |
);
|
| 462 |
res.json({
|
| 463 |
success: true,
|
|
|
|
| 728 |
}
|
| 729 |
});
|
| 730 |
|
| 731 |
+
// Utility endpoint to update old submissions: set card_type and payment_method to 'oldsub' where missing
|
| 732 |
+
app.post('/api/admin/fix-old-submissions', async (req, res) => {
|
| 733 |
+
try {
|
| 734 |
+
const result = await getPool().query(
|
| 735 |
+
`UPDATE submissions
|
| 736 |
+
SET card_type = 'oldsub', payment_method = 'oldsub'
|
| 737 |
+
WHERE (card_type IS NULL OR card_type = '')
|
| 738 |
+
OR (payment_method IS NULL OR payment_method = '')
|
| 739 |
+
RETURNING id`);
|
| 740 |
+
res.json({
|
| 741 |
+
success: true,
|
| 742 |
+
updatedCount: result.rows.length,
|
| 743 |
+
updatedIds: result.rows.map(r => r.id)
|
| 744 |
+
});
|
| 745 |
+
} catch (error) {
|
| 746 |
+
console.error('Error updating old submissions:', error);
|
| 747 |
+
res.status(500).json({ success: false, error: 'Failed to update old submissions' });
|
| 748 |
+
}
|
| 749 |
+
});
|
| 750 |
+
|
| 751 |
// Check if submission is open (Sunday 9am-9pm)
|
| 752 |
app.get('/isubmissionopen', (req, res) => {
|
| 753 |
const now = new Date();
|