-
Notifications
You must be signed in to change notification settings - Fork 0
Add ReservationRequestCreated integration event to notify listing owners #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: rohit-r-kumar <175348946+rohit-r-kumar@users.noreply.github.com>
Co-authored-by: rohit-r-kumar <175348946+rohit-r-kumar@users.noreply.github.com>
Co-authored-by: rohit-r-kumar <175348946+rohit-r-kumar@users.noreply.github.com>
|
@copilot Because for the event you are making, you are using the generic email service interface as a parameter into that service file being used by the event handler and calling it using the information needed from the database using the domaindatasource |
|
@rohit-r-kumar Unfortunately I hit an unexpected error while processing your comment. I've automatically reported this to GitHub. You can ask me to try again later by mentioning me in a new comment. If you want to contact GitHub about this error, please mention the following identifier so they can better serve you: Sorry for the inconvenience! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements an integration event system to notify listing owners when their item receives a reservation request, following CellixJS's event-driven architecture patterns. The implementation introduces a new domain event (ReservationRequestCreatedEvent) that is fired when a reservation request is created and handled asynchronously by an event handler that prepares email notification data.
Key Changes
- Created domain event
ReservationRequestCreatedEventwith typed payload for reservation details - Implemented async event handler that fetches related entities (sharer, reserver, listing) using system passport
- Updated dependency injection to pass
DataSourcesFactoryandSendGridservice to event handlers
Reviewed Changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/sthrift/domain/src/domain/events/types/reservation-request-created.ts | Defines the integration event class with typed payload interface for reservation request creation |
| packages/sthrift/domain/src/domain/contexts/reservation-request/reservation-request/reservation-request.ts | Fires integration event in getNewInstance() with reservation and listing details |
| packages/sthrift/event-handler/src/handlers/integration/reservation-request-created--notify-sharer.ts | Async handler that fetches entities and prepares notification data; registered with NodeEventBusInstance |
| packages/sthrift/event-handler/src/handlers/integration/index.ts | Registers the new handler with DataSourcesFactory and SendGrid dependencies |
| apps/api/src/index.ts | Instantiates SendGrid service and passes it to event handler registration |
| packages/sthrift/event-handler/package.json | Adds dependencies for event bus, persistence, and SendGrid service |
| pnpm-lock.yaml | Updates workspace dependencies to include new event-handler package dependencies |
| packages/sthrift/domain/src/domain/index.ts | Exports event types from domain package for handler access |
| packages/sthrift/domain/src/domain/events/index.ts | Re-exports event type definitions |
| packages/sthrift/domain/src/domain/events/types/index.ts | Exports ReservationRequestCreatedEvent |
| packages/sthrift/event-handler/src/handlers/index.ts | Updates signature to accept DataSourcesFactory and SendGrid parameters |
| packages/sthrift/event-handler/src/handlers/domain/index.ts | Updates to use DataSourcesFactory instead of DomainDataSource |
| apps/api/package.json | Adds SendGrid service dependency to API package |
Files not reviewed (1)
- pnpm-lock.yaml: Language not supported
|
|
||
| export const ReservationRequestCreatedNotifySharerHandler = ( | ||
| dataSourcesFactory: DataSourcesFactory, | ||
| _sendGridService: SendGrid, |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The _sendGridService parameter is prefixed with an underscore indicating it's intentionally unused, but it's passed to the registration function. Since the handler currently only logs email details (as indicated by the TODO comment), consider removing this parameter until the actual email sending is implemented to avoid passing unnecessary dependencies.
| return async (payload: { | ||
| reservationRequestId: string; | ||
| listingId: string; | ||
| reserverId: string; | ||
| sharerId: string; | ||
| reservationPeriodStart: Date; | ||
| reservationPeriodEnd: Date; | ||
| }) => { |
Copilot
AI
Nov 19, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The handler manually defines the payload interface inline, which duplicates the type definition from ReservationRequestCreatedProps. This creates a maintenance burden if the event payload structure changes. Import and use ReservationRequestCreatedProps from the domain layer instead:
import type { ReservationRequestCreatedProps } from '@sthrift/domain';
// ...
return async (payload: ReservationRequestCreatedProps) => {…endGrid type Co-authored-by: rohit-r-kumar <175348946+rohit-r-kumar@users.noreply.github.com>
Updated to use the generic Changes in commit d9097ad:
This follows DDD principles by depending on abstractions rather than concrete implementations. |
Implements an integration event that notifies listing owners when their item receives a reservation request, following the community-created event pattern in CellixJS.
Changes
Domain Layer
ReservationRequestCreatedEventwith payload containing reservation details (IDs, dates)ReservationRequest.getNewInstance()to fire integration event on creationTransactionalEmailServiceinterface in domain services following DDD principlesEvent Handler
TransactionalEmailServiceinterface (not concrete SendGrid type)NodeEventBusInstancefor async processingInfrastructure
TransactionalEmailServiceinterfacesendReservationNotification()method to SendGrid serviceDataSourcesFactoryand email service interface to event handlersEmail Implementation
tmp-emails/folder as text filesExample Usage
Handler fetches all necessary data and sends notification:
Architecture Benefits
TransactionalEmailServiceabstraction, not concrete SendGrid implementationRemaining Work
Create proper HTML email template in
assets/email-templates/Add unit tests for event handler
Fixes event for ReservationRequestCreation #287
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.