fixed cors bug, separating rental confirmation for owner and renter, removing condition checks from my-listings

This commit is contained in:
jackiettran
2025-10-08 23:03:28 -04:00
parent 052781a0e6
commit 34c0ad2920
5 changed files with 249 additions and 94 deletions

View File

@@ -415,6 +415,11 @@ class EmailService {
}
async sendRentalConfirmationEmails(rental) {
const results = {
ownerEmailSent: false,
renterEmailSent: false,
};
try {
// Get owner and renter emails
const owner = await User.findByPk(rental.ownerId, {
@@ -444,30 +449,67 @@ class EmailService {
metadata: { rentalStart: rental.startDateTime },
};
// Send email to owner
// Send email to owner - independent error handling
if (owner?.email) {
await this.sendRentalConfirmation(
owner.email,
ownerNotification,
rental
);
console.log(`Rental confirmation email sent to owner: ${owner.email}`);
try {
const ownerResult = await this.sendRentalConfirmation(
owner.email,
ownerNotification,
rental
);
if (ownerResult.success) {
console.log(
`Rental confirmation email sent to owner: ${owner.email}`
);
results.ownerEmailSent = true;
} else {
console.error(
`Failed to send rental confirmation email to owner (${owner.email}):`,
ownerResult.error
);
}
} catch (error) {
console.error(
`Failed to send rental confirmation email to owner (${owner.email}):`,
error.message
);
}
}
// Send email to renter
// Send email to renter - independent error handling
if (renter?.email) {
await this.sendRentalConfirmation(
renter.email,
renterNotification,
rental
);
console.log(
`Rental confirmation email sent to renter: ${renter.email}`
);
try {
const renterResult = await this.sendRentalConfirmation(
renter.email,
renterNotification,
rental
);
if (renterResult.success) {
console.log(
`Rental confirmation email sent to renter: ${renter.email}`
);
results.renterEmailSent = true;
} else {
console.error(
`Failed to send rental confirmation email to renter (${renter.email}):`,
renterResult.error
);
}
} catch (error) {
console.error(
`Failed to send rental confirmation email to renter (${renter.email}):`,
error.message
);
}
}
} catch (error) {
console.error("Error sending rental confirmation emails:", error);
console.error(
"Error fetching user data for rental confirmation emails:",
error
);
}
return results;
}
}