Update notification in SendUpcomingNotificationService tracking to create EmailEvent records

Problem

Currently, the SendUpcomingNotificationService tracks sent notifications by updating a timestamp field on the Order model (upcoming_auto_renewal_notified_at). This approach lacks detailed tracking of which notifications were sent, to whom, and when. With our new Notifications::EmailEvent model, we need to update the service to create proper EmailEvent records for better tracking and analysis.

Proposal

Modify the SendUpcomingNotificationService to create Notifications::EmailEvent records when emails are sent. This will involve:

  1. Updating the notification_successful method to create an EmailEvent record after successfully sending an email
  2. Including relevant metadata such as notification type, recipient, and order details in the EmailEvent record
  3. Modifying the "already notified" check to use EmailEvent records instead of the timestamp field
  4. Ensuring proper error handling and logging for EmailEvent creation

Result

  • Detailed tracking of all sent notifications in the EmailEvent table

How will we measure success?

  • EmailEvent records are created for every notification sent
  • The records contain accurate information about the notification
  • The system correctly prevents duplicate notifications based on EmailEvent records