Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Nov 19, 2025

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

  • Created ReservationRequestCreatedEvent with payload containing reservation details (IDs, dates)
  • Modified ReservationRequest.getNewInstance() to fire integration event on creation
  • Created TransactionalEmailService interface in domain services following DDD principles

Event Handler

  • Added handler that fetches sharer, reserver, and listing data using system passport
  • Calls transactional email service to send notification emails
  • Uses generic TransactionalEmailService interface (not concrete SendGrid type)
  • Registered with NodeEventBusInstance for async processing

Infrastructure

  • SendGrid service implements TransactionalEmailService interface
  • Added sendReservationNotification() method to SendGrid service
  • Passed DataSourcesFactory and email service interface to event handlers
  • Email service injected as dependency similar to DataSourcesFactory pattern

Email Implementation

  • Development mode: saves emails to tmp-emails/ folder as text files
  • Production mode: sends actual emails via SendGrid API
  • Email includes reserver name, listing title, and reservation dates

Example Usage

// Event fires automatically when reservation is created
const newReservationRequest = await repo.getNewInstance(
    'Requested',
    listing,
    reserver,
    reservationPeriodStart,
    reservationPeriodEnd
);
// Integration event dispatched asynchronously, separate transaction
await repo.save(newReservationRequest);

Handler fetches all necessary data and sends notification:

// Email is sent with:
// To: sharer.account.email
// Subject: New reservation request for [listing.title]
// Body: [reserverName] has requested to reserve [listing.title] from [start] to [end]

Architecture Benefits

  • Follows DDD: depends on TransactionalEmailService abstraction, not concrete SendGrid implementation
  • Easy to swap email providers by creating new implementations
  • Email service passed as parameter alongside DataSourcesFactory as requested

Remaining Work

Original prompt

This section details on the original issue you should resolve

<issue_title>event for ReservationRequestCreation</issue_title>
<issue_description>https://github.com/CellixJs/cellixjs/tree/main

packages/ocom/domain/src/domain/events/types/community-created.ts
packages/ocom/domain/src/domain/services/community/community-provisioning.service.ts
packages/ocom/domain/src/domain/contexts/community/community/community.ts
packages/ocom/event-handler/src/handlers/integration/community-created--provision-member-and-default-role.ts
apps/api/src/index.ts

Create an event for ReservationRequestCreation, should behave in a similar way to how community creation is handled in cellix, but the actual service being called by the event handler will have its functionality changed. It should instead fetch relevant infomration bout the user needed for the transactional-email-service function being called, then also taking a dependency and receiving a parameter of that service, in a similar way to how domaindatasource is passed down in the cellix service, call the transactional-email-servic and send an email to the sharer of the listing that the reservation request is connected to. So in simpler terms notifiying the listing owner that their listing was reserved.

</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 19, 2025 07:55
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 AI changed the title [WIP] Add event for ReservationRequestCreation handling Add ReservationRequestCreated integration event to notify listing owners Nov 19, 2025
Copilot AI requested a review from rohit-r-kumar November 19, 2025 08:18
@rohit-r-kumar
Copy link
Contributor

@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

Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@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: 0d79e059-b5b4-4ad8-8994-e4073c39fae3

Sorry for the inconvenience!

Copy link
Contributor

Copilot AI left a 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 ReservationRequestCreatedEvent with typed payload for reservation details
  • Implemented async event handler that fetches related entities (sharer, reserver, listing) using system passport
  • Updated dependency injection to pass DataSourcesFactory and SendGrid service 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,
Copy link

Copilot AI Nov 19, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 10 to 17
return async (payload: {
reservationRequestId: string;
listingId: string;
reserverId: string;
sharerId: string;
reservationPeriodStart: Date;
reservationPeriodEnd: Date;
}) => {
Copy link

Copilot AI Nov 19, 2025

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) => {

Copilot uses AI. Check for mistakes.
…endGrid type

Co-authored-by: rohit-r-kumar <175348946+rohit-r-kumar@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Nov 19, 2025

@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 informat...

Updated to use the generic TransactionalEmailService interface from domain services instead of the concrete SendGrid type.

Changes in commit d9097ad:

  • Created TransactionalEmailService interface in domain services
  • SendGrid now implements this interface
  • Event handler accepts Domain.Services['TransactionalEmailService'] parameter
  • Fully implemented sendReservationNotification() method
  • Email service is passed to event handlers alongside DataSourcesFactory

This follows DDD principles by depending on abstractions rather than concrete implementations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

event for ReservationRequestCreation

2 participants