replaced some console.errors with logger

This commit is contained in:
jackiettran
2026-01-10 20:47:29 -05:00
parent 86cb8b3fe0
commit 415bcc5021
15 changed files with 165 additions and 174 deletions

View File

@@ -729,7 +729,7 @@ router.patch('/posts/:id/status', authenticateToken, async (req, res, next) => {
stack: emailError.stack, stack: emailError.stack,
postId: req.params.id postId: req.params.id
}); });
console.error("Email notification error:", emailError); logger.error("Email notification error", { error: emailError });
} }
})(); })();
} }
@@ -909,7 +909,7 @@ router.patch('/posts/:id/accept-answer', authenticateToken, async (req, res, nex
commentId: commentId, commentId: commentId,
postId: req.params.id postId: req.params.id
}); });
console.error("Email notification error:", emailError); logger.error("Email notification error", { error: emailError });
} }
})(); })();
} }
@@ -1109,7 +1109,7 @@ router.post('/posts/:id/comments', authenticateToken, async (req, res, next) =>
commentId: comment.id, commentId: comment.id,
postId: req.params.id postId: req.params.id
}); });
console.error("Email notification error:", emailError); logger.error("Email notification error", { error: emailError });
} }
})(); })();
@@ -1689,7 +1689,7 @@ router.patch('/admin/posts/:id/close', authenticateToken, requireAdmin, async (r
stack: emailError.stack, stack: emailError.stack,
postId: req.params.id postId: req.params.id
}); });
console.error("Email notification error:", emailError); logger.error("Email notification error", { error: emailError });
} }
})(); })();

View File

@@ -269,7 +269,7 @@ router.put('/profile', authenticateToken, async (req, res, next) => {
res.json(updatedUser); res.json(updatedUser);
} catch (error) { } catch (error) {
console.error('Profile update error:', error); logger.error('Profile update error', { error });
next(error); next(error);
} }
}); });

View File

@@ -1,6 +1,7 @@
const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses"); const { SESClient, SendEmailCommand } = require("@aws-sdk/client-ses");
const { getAWSConfig } = require("../../../config/aws"); const { getAWSConfig } = require("../../../config/aws");
const { htmlToPlainText } = require("./emailUtils"); const { htmlToPlainText } = require("./emailUtils");
const logger = require("../../../utils/logger");
/** /**
* EmailClient handles AWS SES configuration and core email sending functionality * EmailClient handles AWS SES configuration and core email sending functionality
@@ -44,9 +45,9 @@ class EmailClient {
this.sesClient = new SESClient(awsConfig); this.sesClient = new SESClient(awsConfig);
this.initialized = true; this.initialized = true;
console.log("AWS SES Email Client initialized successfully"); logger.info("AWS SES Email Client initialized successfully");
} catch (error) { } catch (error) {
console.error("Failed to initialize AWS SES Email Client:", error); logger.error("Failed to initialize AWS SES Email Client", { error });
throw error; throw error;
} }
})(); })();
@@ -69,7 +70,7 @@ class EmailClient {
// Check if email sending is enabled in the environment // Check if email sending is enabled in the environment
if (!process.env.EMAIL_ENABLED || process.env.EMAIL_ENABLED !== "true") { if (!process.env.EMAIL_ENABLED || process.env.EMAIL_ENABLED !== "true") {
console.log("Email sending disabled in environment"); logger.debug("Email sending disabled in environment");
return { success: true, messageId: "disabled" }; return { success: true, messageId: "disabled" };
} }
@@ -115,12 +116,10 @@ class EmailClient {
const command = new SendEmailCommand(params); const command = new SendEmailCommand(params);
const result = await this.sesClient.send(command); const result = await this.sesClient.send(command);
console.log( logger.info("Email sent successfully", { to, messageId: result.MessageId });
`Email sent successfully to ${to}, MessageId: ${result.MessageId}`
);
return { success: true, messageId: result.MessageId }; return { success: true, messageId: result.MessageId };
} catch (error) { } catch (error) {
console.error("Failed to send email:", error); logger.error("Failed to send email", { error, to });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,5 +1,6 @@
const fs = require("fs").promises; const fs = require("fs").promises;
const path = require("path"); const path = require("path");
const logger = require("../../../utils/logger");
/** /**
* TemplateManager handles loading, caching, and rendering email templates * TemplateManager handles loading, caching, and rendering email templates
@@ -40,7 +41,7 @@ class TemplateManager {
this.initializationPromise = (async () => { this.initializationPromise = (async () => {
await this.loadEmailTemplates(); await this.loadEmailTemplates();
this.initialized = true; this.initialized = true;
console.log("Email Template Manager initialized successfully"); logger.info("Email Template Manager initialized successfully");
})(); })();
return this.initializationPromise; return this.initializationPromise;
@@ -118,22 +119,21 @@ class TemplateManager {
const templateContent = await fs.readFile(templatePath, "utf-8"); const templateContent = await fs.readFile(templatePath, "utf-8");
const templateName = path.basename(templateFile, ".html"); const templateName = path.basename(templateFile, ".html");
this.templates.set(templateName, templateContent); this.templates.set(templateName, templateContent);
console.log(`Loaded template: ${templateName}`); logger.debug("Loaded template", { templateName });
} catch (error) { } catch (error) {
console.error( logger.error("Failed to load template", {
`✗ Failed to load template ${templateFile}:`, templateFile,
error.message templatePath: path.join(templatesDir, templateFile),
); error,
console.error( });
` Template path: ${path.join(templatesDir, templateFile)}`
);
failedTemplates.push(templateFile); failedTemplates.push(templateFile);
} }
} }
console.log( logger.info("Loaded email templates", {
`Loaded ${this.templates.size} of ${templateFiles.length} email templates` loaded: this.templates.size,
); total: templateFiles.length,
});
// Check if critical templates are missing // Check if critical templates are missing
const missingCriticalTemplates = criticalTemplates.filter( const missingCriticalTemplates = criticalTemplates.filter(
@@ -152,17 +152,15 @@ class TemplateManager {
// Warn if non-critical templates failed // Warn if non-critical templates failed
if (failedTemplates.length > 0) { if (failedTemplates.length > 0) {
console.warn( logger.warn("Non-critical templates failed to load, using fallback versions", {
`⚠️ Non-critical templates failed to load: ${failedTemplates.join( failedTemplates,
", " });
)}`
);
console.warn("These templates will use fallback versions");
} }
} catch (error) { } catch (error) {
console.error("Failed to load email templates:", error); logger.error("Failed to load email templates", {
console.error("Templates directory:", templatesDir); templatesDir,
console.error("Error stack:", error.stack); error,
});
throw error; // Re-throw to fail server startup throw error; // Re-throw to fail server startup
} }
} }
@@ -176,22 +174,20 @@ class TemplateManager {
async renderTemplate(templateName, variables = {}) { async renderTemplate(templateName, variables = {}) {
// Ensure service is initialized before rendering // Ensure service is initialized before rendering
if (!this.initialized) { if (!this.initialized) {
console.log(`Template manager not initialized yet, initializing now...`); logger.debug("Template manager not initialized yet, initializing now...");
await this.initialize(); await this.initialize();
} }
let template = this.templates.get(templateName); let template = this.templates.get(templateName);
if (!template) { if (!template) {
console.error(`Template not found: ${templateName}`); logger.error("Template not found, using fallback", {
console.error( templateName,
`Available templates: ${Array.from(this.templates.keys()).join(", ")}` availableTemplates: Array.from(this.templates.keys()),
); });
console.error(`Stack trace:`, new Error().stack);
console.log(`Using fallback template for: ${templateName}`);
template = this.getFallbackTemplate(templateName); template = this.getFallbackTemplate(templateName);
} else { } else {
console.log(`Template found: ${templateName}`); logger.debug("Template found", { templateName });
} }
let rendered = template; let rendered = template;
@@ -202,9 +198,11 @@ class TemplateManager {
rendered = rendered.replace(regex, variables[key] || ""); rendered = rendered.replace(regex, variables[key] || "");
}); });
} catch (error) { } catch (error) {
console.error(`Error rendering template ${templateName}:`, error); logger.error("Error rendering template", {
console.error(`Stack trace:`, error.stack); templateName,
console.error(`Variables provided:`, Object.keys(variables)); variableKeys: Object.keys(variables),
error,
});
} }
return rendered; return rendered;

View File

@@ -1,5 +1,6 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const logger = require("../../../utils/logger");
/** /**
* AlphaInvitationEmailService handles alpha program invitation emails * AlphaInvitationEmailService handles alpha program invitation emails
@@ -26,7 +27,7 @@ class AlphaInvitationEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Alpha Invitation Email Service initialized successfully"); logger.info("Alpha Invitation Email Service initialized successfully");
} }
/** /**
@@ -62,7 +63,7 @@ class AlphaInvitationEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send alpha invitation email:", error); logger.error("Failed to send alpha invitation email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,5 +1,6 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const logger = require("../../../utils/logger");
/** /**
* CustomerServiceEmailService handles all customer service alert emails * CustomerServiceEmailService handles all customer service alert emails
@@ -28,7 +29,7 @@ class CustomerServiceEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Customer Service Email Service initialized successfully"); logger.info("Customer Service Email Service initialized successfully");
} }
/** /**
@@ -59,7 +60,7 @@ class CustomerServiceEmailService {
try { try {
const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL; const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL;
if (!csEmail) { if (!csEmail) {
console.warn("No customer service email configured"); logger.warn("No customer service email configured");
return { success: false, error: "No customer service email configured" }; return { success: false, error: "No customer service email configured" };
} }
@@ -92,14 +93,14 @@ class CustomerServiceEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Late return notification sent to customer service for rental ${rental.id}` `Late return notification sent to customer service for rental ${rental.id}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send late return notification to customer service:", "Failed to send late return notification to customer service:",
error error
); );
@@ -148,7 +149,7 @@ class CustomerServiceEmailService {
try { try {
const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL; const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL;
if (!csEmail) { if (!csEmail) {
console.warn("No customer service email configured"); logger.warn("No customer service email configured");
return { success: false, error: "No customer service email configured" }; return { success: false, error: "No customer service email configured" };
} }
@@ -206,14 +207,14 @@ class CustomerServiceEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Damage report notification sent to customer service for rental ${rental.id}` `Damage report notification sent to customer service for rental ${rental.id}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send damage report notification to customer service:", "Failed to send damage report notification to customer service:",
error error
); );
@@ -248,7 +249,7 @@ class CustomerServiceEmailService {
try { try {
const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL; const csEmail = process.env.CUSTOMER_SUPPORT_EMAIL;
if (!csEmail) { if (!csEmail) {
console.warn("No customer service email configured"); logger.warn("No customer service email configured");
return { success: false, error: "No customer service email configured" }; return { success: false, error: "No customer service email configured" };
} }
@@ -280,14 +281,14 @@ class CustomerServiceEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Lost item notification sent to customer service for rental ${rental.id}` `Lost item notification sent to customer service for rental ${rental.id}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send lost item notification to customer service:", "Failed to send lost item notification to customer service:",
error error
); );

View File

@@ -1,5 +1,6 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const logger = require("../../../utils/logger");
/** /**
* ForumEmailService handles all forum-related email notifications * ForumEmailService handles all forum-related email notifications
@@ -31,7 +32,7 @@ class ForumEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Forum Email Service initialized successfully"); logger.info("Forum Email Service initialized successfully");
} }
/** /**
@@ -88,14 +89,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum comment notification email sent to ${postAuthor.email}` `Forum comment notification email sent to ${postAuthor.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error("Failed to send forum comment notification email:", error); logger.error("Failed to send forum comment notification email:", error);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -163,14 +164,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum reply notification email sent to ${commentAuthor.email}` `Forum reply notification email sent to ${commentAuthor.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error("Failed to send forum reply notification email:", error); logger.error("Failed to send forum reply notification email:", error);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -227,14 +228,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum answer accepted notification email sent to ${commentAuthor.email}` `Forum answer accepted notification email sent to ${commentAuthor.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send forum answer accepted notification email:", "Failed to send forum answer accepted notification email:",
error error
); );
@@ -301,14 +302,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum thread activity notification email sent to ${participant.email}` `Forum thread activity notification email sent to ${participant.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send forum thread activity notification email:", "Failed to send forum thread activity notification email:",
error error
); );
@@ -372,14 +373,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum post closed notification email sent to ${recipient.email}` `Forum post closed notification email sent to ${recipient.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send forum post closed notification email:", "Failed to send forum post closed notification email:",
error error
); );
@@ -432,14 +433,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum post deletion notification email sent to ${postAuthor.email}` `Forum post deletion notification email sent to ${postAuthor.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send forum post deletion notification email:", "Failed to send forum post deletion notification email:",
error error
); );
@@ -494,14 +495,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Forum comment deletion notification email sent to ${commentAuthor.email}` `Forum comment deletion notification email sent to ${commentAuthor.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error( logger.error(
"Failed to send forum comment deletion notification email:", "Failed to send forum comment deletion notification email:",
error error
); );
@@ -557,14 +558,14 @@ class ForumEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Item request notification email sent to ${recipient.email}` `Item request notification email sent to ${recipient.email}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error("Failed to send item request notification email:", error); logger.error("Failed to send item request notification email:", error);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,5 +1,6 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const logger = require("../../../utils/logger");
/** /**
* MessagingEmailService handles all messaging-related email notifications * MessagingEmailService handles all messaging-related email notifications
@@ -26,7 +27,7 @@ class MessagingEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Messaging Email Service initialized successfully"); logger.info("Messaging Email Service initialized successfully");
} }
/** /**
@@ -79,14 +80,14 @@ class MessagingEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info(
`Message notification email sent to ${receiver.email} from ${sender.firstName} ${sender.lastName}` `Message notification email sent to ${receiver.email} from ${sender.firstName} ${sender.lastName}`
); );
} }
return result; return result;
} catch (error) { } catch (error) {
console.error("Failed to send message notification email:", error); logger.error("Failed to send message notification email:", error);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,6 +1,7 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const { formatEmailDate } = require("../core/emailUtils"); const { formatEmailDate } = require("../core/emailUtils");
const logger = require("../../../utils/logger");
/** /**
* PaymentEmailService handles payment-related emails * PaymentEmailService handles payment-related emails
@@ -28,7 +29,7 @@ class PaymentEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Payment Email Service initialized successfully"); logger.info("Payment Email Service initialized successfully");
} }
/** /**
@@ -73,7 +74,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send payment declined notification:", error); logger.error("Failed to send payment declined notification", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -113,7 +114,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send payment method updated notification:", error); logger.error("Failed to send payment method updated notification", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -168,7 +169,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send payout failed notification:", error); logger.error("Failed to send payout failed notification", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -208,7 +209,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send account disconnected email:", error); logger.error("Failed to send account disconnected email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -248,7 +249,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send payouts disabled email:", error); logger.error("Failed to send payouts disabled email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -300,7 +301,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send dispute alert email:", error); logger.error("Failed to send dispute alert email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -343,7 +344,7 @@ class PaymentEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send dispute lost alert email:", error); logger.error("Failed to send dispute lost alert email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -34,7 +34,7 @@ class RentalFlowEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Rental Flow Email Service initialized successfully"); logger.info("Rental Flow Email Service initialized successfully");
} }
/** /**
@@ -104,7 +104,7 @@ class RentalFlowEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send rental request email:", error); logger.error("Failed to send rental request email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -171,7 +171,7 @@ class RentalFlowEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send rental request confirmation email:", error); logger.error("Failed to send rental request confirmation email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -324,10 +324,7 @@ class RentalFlowEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error( logger.error("Failed to send rental approval confirmation email", { error });
"Failed to send rental approval confirmation email:",
error
);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -410,7 +407,7 @@ class RentalFlowEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send rental declined email:", error); logger.error("Failed to send rental declined email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -544,7 +541,7 @@ class RentalFlowEmailService {
return await this.emailClient.sendEmail(userEmail, subject, htmlContent); return await this.emailClient.sendEmail(userEmail, subject, htmlContent);
} catch (error) { } catch (error) {
console.error("Failed to send rental confirmation:", error); logger.error("Failed to send rental confirmation", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -608,21 +605,19 @@ class RentalFlowEmailService {
false // isRenter = false for owner false // isRenter = false for owner
); );
if (ownerResult.success) { if (ownerResult.success) {
console.log( logger.info("Rental confirmation email sent to owner", { email: owner.email });
`Rental confirmation email sent to owner: ${owner.email}`
);
results.ownerEmailSent = true; results.ownerEmailSent = true;
} else { } else {
console.error( logger.error("Failed to send rental confirmation email to owner", {
`Failed to send rental confirmation email to owner (${owner.email}):`, email: owner.email,
ownerResult.error error: ownerResult.error,
); });
} }
} catch (error) { } catch (error) {
console.error( logger.error("Failed to send rental confirmation email to owner", {
`Failed to send rental confirmation email to owner (${owner.email}):`, email: owner.email,
error.message error,
); });
} }
} }
@@ -637,28 +632,23 @@ class RentalFlowEmailService {
true // isRenter = true for renter (enables payment receipt) true // isRenter = true for renter (enables payment receipt)
); );
if (renterResult.success) { if (renterResult.success) {
console.log( logger.info("Rental confirmation email sent to renter", { email: renter.email });
`Rental confirmation email sent to renter: ${renter.email}`
);
results.renterEmailSent = true; results.renterEmailSent = true;
} else { } else {
console.error( logger.error("Failed to send rental confirmation email to renter", {
`Failed to send rental confirmation email to renter (${renter.email}):`, email: renter.email,
renterResult.error error: renterResult.error,
); });
} }
} catch (error) { } catch (error) {
console.error( logger.error("Failed to send rental confirmation email to renter", {
`Failed to send rental confirmation email to renter (${renter.email}):`, email: renter.email,
error.message error,
); });
} }
} }
} catch (error) { } catch (error) {
console.error( logger.error("Error fetching user data for rental confirmation emails", { error });
"Error fetching user data for rental confirmation emails:",
error
);
} }
return results; return results;
@@ -824,16 +814,17 @@ class RentalFlowEmailService {
); );
if (confirmationResult.success) { if (confirmationResult.success) {
console.log( logger.info("Cancellation confirmation email sent", {
`Cancellation confirmation email sent to ${cancelledBy}: ${confirmationRecipient}` cancelledBy,
); email: confirmationRecipient,
});
results.confirmationEmailSent = true; results.confirmationEmailSent = true;
} }
} catch (error) { } catch (error) {
console.error( logger.error("Failed to send cancellation confirmation email", {
`Failed to send cancellation confirmation email to ${cancelledBy}:`, cancelledBy,
error.message error,
); });
} }
// Send notification email to other party // Send notification email to other party
@@ -860,21 +851,17 @@ class RentalFlowEmailService {
); );
if (notificationResult.success) { if (notificationResult.success) {
console.log( logger.info("Cancellation notification email sent", {
`Cancellation notification email sent to ${ recipientType: cancelledBy === "owner" ? "renter" : "owner",
cancelledBy === "owner" ? "renter" : "owner" email: notificationRecipient,
}: ${notificationRecipient}` });
);
results.notificationEmailSent = true; results.notificationEmailSent = true;
} }
} catch (error) { } catch (error) {
console.error( logger.error("Failed to send cancellation notification email", { error });
`Failed to send cancellation notification email:`,
error.message
);
} }
} catch (error) { } catch (error) {
console.error("Error sending cancellation emails:", error); logger.error("Error sending cancellation emails", { error });
} }
return results; return results;
@@ -991,15 +978,13 @@ class RentalFlowEmailService {
); );
if (renterResult.success) { if (renterResult.success) {
console.log( logger.info("Rental completion thank you email sent to renter", { email: renter.email });
`Rental completion thank you email sent to renter: ${renter.email}`
);
results.renterEmailSent = true; results.renterEmailSent = true;
} else { } else {
console.error( logger.error("Failed to send rental completion email to renter", {
`Failed to send rental completion email to renter (${renter.email}):`, email: renter.email,
renterResult.error error: renterResult.error,
); });
} }
} catch (emailError) { } catch (emailError) {
logger.error("Failed to send rental completion email to renter", { logger.error("Failed to send rental completion email to renter", {
@@ -1111,15 +1096,13 @@ class RentalFlowEmailService {
); );
if (ownerResult.success) { if (ownerResult.success) {
console.log( logger.info("Rental completion congratulations email sent to owner", { email: owner.email });
`Rental completion congratulations email sent to owner: ${owner.email}`
);
results.ownerEmailSent = true; results.ownerEmailSent = true;
} else { } else {
console.error( logger.error("Failed to send rental completion email to owner", {
`Failed to send rental completion email to owner (${owner.email}):`, email: owner.email,
ownerResult.error error: ownerResult.error,
); });
} }
} catch (emailError) { } catch (emailError) {
logger.error("Failed to send rental completion email to owner", { logger.error("Failed to send rental completion email to owner", {
@@ -1205,7 +1188,7 @@ class RentalFlowEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send payout received email:", error); logger.error("Failed to send payout received email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -1249,7 +1232,7 @@ class RentalFlowEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send authentication required email:", error); logger.error("Failed to send authentication required email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,5 +1,6 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const logger = require("../../../utils/logger");
/** /**
* RentalReminderEmailService handles rental reminder emails * RentalReminderEmailService handles rental reminder emails
@@ -26,7 +27,7 @@ class RentalReminderEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("Rental Reminder Email Service initialized successfully"); logger.info("Rental Reminder Email Service initialized successfully");
} }
/** /**
@@ -68,7 +69,7 @@ class RentalReminderEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send condition check reminder:", error); logger.error("Failed to send condition check reminder:", error);
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,5 +1,6 @@
const EmailClient = require("../core/EmailClient"); const EmailClient = require("../core/EmailClient");
const TemplateManager = require("../core/TemplateManager"); const TemplateManager = require("../core/TemplateManager");
const logger = require("../../../utils/logger");
/** /**
* UserEngagementEmailService handles user engagement emails * UserEngagementEmailService handles user engagement emails
@@ -27,7 +28,7 @@ class UserEngagementEmailService {
]); ]);
this.initialized = true; this.initialized = true;
console.log("User Engagement Email Service initialized successfully"); logger.info("User Engagement Email Service initialized successfully");
} }
/** /**
@@ -68,7 +69,7 @@ class UserEngagementEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send first listing celebration email:", error); logger.error("Failed to send first listing celebration email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -114,7 +115,7 @@ class UserEngagementEmailService {
htmlContent htmlContent
); );
} catch (error) { } catch (error) {
console.error("Failed to send item deletion notification email:", error); logger.error("Failed to send item deletion notification email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }
@@ -158,14 +159,14 @@ class UserEngagementEmailService {
); );
if (result.success) { if (result.success) {
console.log( logger.info("User banned notification email sent", {
`User banned notification email sent to ${bannedUser.email}` email: bannedUser.email,
); });
} }
return result; return result;
} catch (error) { } catch (error) {
console.error("Failed to send user banned notification email:", error); logger.error("Failed to send user banned notification email", { error });
return { success: false, error: error.message }; return { success: false, error: error.message };
} }
} }

View File

@@ -1,4 +1,5 @@
const { Client } = require('@googlemaps/google-maps-services-js'); const { Client } = require('@googlemaps/google-maps-services-js');
const logger = require('../utils/logger');
class GoogleMapsService { class GoogleMapsService {
constructor() { constructor() {
@@ -6,9 +7,9 @@ class GoogleMapsService {
this.apiKey = process.env.GOOGLE_MAPS_API_KEY; this.apiKey = process.env.GOOGLE_MAPS_API_KEY;
if (!this.apiKey) { if (!this.apiKey) {
console.error('Google Maps API key not configured in environment variables'); logger.error('Google Maps API key not configured in environment variables');
} else { } else {
console.log('Google Maps service initialized'); logger.info('Google Maps service initialized');
} }
} }
@@ -61,15 +62,15 @@ class GoogleMapsService {
})) }))
}; };
} else { } else {
console.error('Places Autocomplete API error:', response.data.status, response.data.error_message); logger.error('Places Autocomplete API error', { status: response.data.status, errorMessage: response.data.error_message });
return { return {
predictions: [], predictions: [],
error: this.getErrorMessage(response.data.status), error: this.getErrorMessage(response.data.status),
status: response.data.status status: response.data.status
}; };
} }
} catch (error) { } catch (error) {
console.error('Places Autocomplete service error:', error.message); logger.error('Places Autocomplete service error', { error });
throw new Error('Failed to fetch place predictions'); throw new Error('Failed to fetch place predictions');
} }
} }
@@ -145,11 +146,11 @@ class GoogleMapsService {
} }
}; };
} else { } else {
console.error('Place Details API error:', response.data.status, response.data.error_message); logger.error('Place Details API error', { status: response.data.status, errorMessage: response.data.error_message });
throw new Error(this.getErrorMessage(response.data.status)); throw new Error(this.getErrorMessage(response.data.status));
} }
} catch (error) { } catch (error) {
console.error('Place Details service error:', error.message); logger.error('Place Details service error', { error });
throw error; throw error;
} }
} }
@@ -200,14 +201,14 @@ class GoogleMapsService {
placeId: result.place_id placeId: result.place_id
}; };
} else { } else {
console.error('Geocoding API error:', response.data.status, response.data.error_message); logger.error('Geocoding API error', { status: response.data.status, errorMessage: response.data.error_message });
return { return {
error: this.getErrorMessage(response.data.status), error: this.getErrorMessage(response.data.status),
status: response.data.status status: response.data.status
}; };
} }
} catch (error) { } catch (error) {
console.error('Geocoding service error:', error.message); logger.error('Geocoding service error', { error });
throw new Error('Failed to geocode address'); throw new Error('Failed to geocode address');
} }
} }

View File

@@ -1,5 +1,6 @@
const { sequelize } = require("../models"); const { sequelize } = require("../models");
const { QueryTypes } = require("sequelize"); const { QueryTypes } = require("sequelize");
const logger = require("../utils/logger");
class LocationService { class LocationService {
/** /**
@@ -71,7 +72,7 @@ class LocationService {
distance: parseFloat(user.distance).toFixed(2), // Round to 2 decimal places distance: parseFloat(user.distance).toFixed(2), // Round to 2 decimal places
})); }));
} catch (error) { } catch (error) {
console.error("Error finding users in radius:", error); logger.error("Error finding users in radius", { error });
throw new Error(`Failed to find users in radius: ${error.message}`); throw new Error(`Failed to find users in radius: ${error.message}`);
} }
} }

View File

@@ -1,6 +1,7 @@
const { Rental } = require("../models"); const { Rental } = require("../models");
const StripeService = require("./stripeService"); const StripeService = require("./stripeService");
const { isActive } = require("../utils/rentalStatus"); const { isActive } = require("../utils/rentalStatus");
const logger = require("../utils/logger");
class RefundService { class RefundService {
/** /**
@@ -161,13 +162,14 @@ class RefundService {
stripeRefundId = refund.id; stripeRefundId = refund.id;
refundProcessedAt = new Date(); refundProcessedAt = new Date();
} catch (error) { } catch (error) {
console.error("Error processing Stripe refund:", error); logger.error("Error processing Stripe refund", { error });
throw new Error(`Failed to process refund: ${error.message}`); throw new Error(`Failed to process refund: ${error.message}`);
} }
} else if (refundCalculation.refundAmount > 0) { } else if (refundCalculation.refundAmount > 0) {
// Log warning if we should refund but don't have payment intent // Log warning if we should refund but don't have payment intent
console.warn( logger.warn(
`Refund amount calculated but no payment intent ID for rental ${rentalId}` "Refund amount calculated but no payment intent ID for rental",
{ rentalId }
); );
} }