diff --git a/backend/src/routes/adminEvents.js b/backend/src/routes/adminEvents.js index 94036da..fe6408b 100644 --- a/backend/src/routes/adminEvents.js +++ b/backend/src/routes/adminEvents.js @@ -8,6 +8,7 @@ const crypto = require('crypto'); const fs = require('fs').promises; const path = require('path'); const { archiveEvent } = require('../services/archiveService'); +const { queueEmail } = require('../services/emailProcessor'); const { escapeLikePattern } = require('../utils/sqlSecurity'); const { formatDate } = require('../utils/dateFormatter'); const { validatePasswordInContext, getBcryptRounds } = require('../utils/passwordValidation'); @@ -540,7 +541,6 @@ router.post('/:id/reset-password', adminAuth, async (req, res) => { // Queue email notification if requested if (sendEmail) { - const { queueEmail } = require('../services/emailProcessor'); // For password reset, we'll need to create a template or use a different approach // For now, let's use the gallery_created template with updated password await queueEmail(id, event.host_email, 'gallery_created', { @@ -583,7 +583,6 @@ router.post('/:id/resend-email', adminAuth, async (req, res) => { const expiryDate = new Date(event.expires_at); // Queue the email - const { queueEmail } = require('../services/emailProcessor'); await queueEmail(id, event.host_email, 'gallery_created', { host_name: event.host_name || event.host_email.split('@')[0], event_name: event.event_name, @@ -595,15 +594,20 @@ router.post('/:id/resend-email', adminAuth, async (req, res) => { eventId: id }); - // Log the activity - await db('activity_logs').insert({ - event_id: id, - ip_address: req.ip, - user_agent: req.get('user-agent'), - action_type: 'email_resent', - action_details: JSON.stringify({ email_type: 'gallery_created' }), - timestamp: new Date() - }); + // Log the activity - wrap in try-catch to prevent failure if activity logging fails + try { + await db('activity_logs').insert({ + event_id: id, + ip_address: req.ip || '0.0.0.0', + user_agent: req.get('user-agent') || 'Unknown', + action_type: 'email_resent', + action_details: JSON.stringify({ email_type: 'gallery_created' }), + timestamp: new Date() + }); + } catch (logError) { + console.error('Warning: Failed to log activity:', logError); + // Don't fail the request if activity logging fails + } res.json({ success: true, @@ -611,6 +615,7 @@ router.post('/:id/resend-email', adminAuth, async (req, res) => { }); } catch (error) { console.error('Error resending creation email:', error); + console.error('Stack trace:', error.stack); res.status(500).json({ error: 'Failed to resend creation email' }); } });