email refactor
This commit is contained in:
@@ -7,7 +7,7 @@ const RentalDurationCalculator = require("../utils/rentalDurationCalculator");
|
||||
const RefundService = require("../services/refundService");
|
||||
const LateReturnService = require("../services/lateReturnService");
|
||||
const DamageAssessmentService = require("../services/damageAssessmentService");
|
||||
const emailService = require("../services/emailService");
|
||||
const emailServices = require("../services/email");
|
||||
const logger = require("../utils/logger");
|
||||
const router = express.Router();
|
||||
|
||||
@@ -302,7 +302,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
|
||||
|
||||
// Send rental request notification to owner
|
||||
try {
|
||||
await emailService.sendRentalRequestEmail(rentalWithDetails);
|
||||
await emailServices.rentalFlow.sendRentalRequestEmail(rentalWithDetails.owner, rentalWithDetails.renter, rentalWithDetails);
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.info("Rental request notification sent to owner", {
|
||||
rentalId: rental.id,
|
||||
@@ -320,7 +320,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
|
||||
|
||||
// Send rental request confirmation to renter
|
||||
try {
|
||||
await emailService.sendRentalRequestConfirmationEmail(rentalWithDetails);
|
||||
await emailServices.rentalFlow.sendRentalRequestConfirmationEmail(rentalWithDetails.renter, rentalWithDetails);
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.info("Rental request confirmation sent to renter", {
|
||||
rentalId: rental.id,
|
||||
@@ -444,7 +444,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
||||
// Send confirmation emails
|
||||
// Send approval confirmation to owner with Stripe reminder
|
||||
try {
|
||||
await emailService.sendRentalApprovalConfirmationEmail(updatedRental);
|
||||
await emailServices.rentalFlow.sendRentalApprovalConfirmationEmail(updatedRental.owner, updatedRental.renter, updatedRental);
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.info("Rental approval confirmation sent to owner", {
|
||||
rentalId: updatedRental.id,
|
||||
@@ -473,7 +473,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
||||
userId: updatedRental.renterId,
|
||||
metadata: { rentalStart: updatedRental.startDateTime },
|
||||
};
|
||||
await emailService.sendRentalConfirmation(
|
||||
await emailServices.rentalFlow.sendRentalConfirmation(
|
||||
renter.email,
|
||||
renterNotification,
|
||||
updatedRental,
|
||||
@@ -536,7 +536,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
||||
// Send confirmation emails
|
||||
// Send approval confirmation to owner (for free rentals, no Stripe reminder shown)
|
||||
try {
|
||||
await emailService.sendRentalApprovalConfirmationEmail(updatedRental);
|
||||
await emailServices.rentalFlow.sendRentalApprovalConfirmationEmail(updatedRental.owner, updatedRental.renter, updatedRental);
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.info("Rental approval confirmation sent to owner", {
|
||||
rentalId: updatedRental.id,
|
||||
@@ -565,7 +565,7 @@ router.put("/:id/status", authenticateToken, async (req, res) => {
|
||||
userId: updatedRental.renterId,
|
||||
metadata: { rentalStart: updatedRental.startDateTime },
|
||||
};
|
||||
await emailService.sendRentalConfirmation(
|
||||
await emailServices.rentalFlow.sendRentalConfirmation(
|
||||
renter.email,
|
||||
renterNotification,
|
||||
updatedRental,
|
||||
@@ -686,7 +686,7 @@ router.put("/:id/decline", authenticateToken, async (req, res) => {
|
||||
|
||||
// Send decline notification email to renter
|
||||
try {
|
||||
await emailService.sendRentalDeclinedEmail(updatedRental, reason);
|
||||
await emailServices.rentalFlow.sendRentalDeclinedEmail(updatedRental.renter, updatedRental, reason);
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.info("Rental decline notification sent to renter", {
|
||||
rentalId: rental.id,
|
||||
@@ -1060,7 +1060,9 @@ router.post("/:id/cancel", authenticateToken, async (req, res) => {
|
||||
|
||||
// Send cancellation notification emails
|
||||
try {
|
||||
await emailService.sendRentalCancellationEmails(
|
||||
await emailServices.rentalFlow.sendRentalCancellationEmails(
|
||||
updatedRental.owner,
|
||||
updatedRental.renter,
|
||||
updatedRental,
|
||||
result.refund
|
||||
);
|
||||
@@ -1153,7 +1155,7 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
||||
|
||||
// Send completion emails to both renter and owner
|
||||
try {
|
||||
await emailService.sendRentalCompletionEmails(rentalWithDetails);
|
||||
await emailServices.rentalFlow.sendRentalCompletionEmails(rentalWithDetails.owner, rentalWithDetails.renter, rentalWithDetails);
|
||||
const reqLogger = logger.withRequestId(req.id);
|
||||
reqLogger.info("Rental completion emails sent", {
|
||||
rentalId,
|
||||
@@ -1221,7 +1223,9 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
|
||||
});
|
||||
|
||||
// Send notification to customer service
|
||||
await emailService.sendLostItemToCustomerService(updatedRental);
|
||||
const owner = await User.findByPk(rental.ownerId);
|
||||
const renter = await User.findByPk(rental.renterId);
|
||||
await emailServices.customerService.sendLostItemToCustomerService(updatedRental, owner, renter);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user