refactor: replace Apollo Client with Prisma for user data retrieval i…#8872
refactor: replace Apollo Client with Prisma for user data retrieval i…#8872mikeallisonJS wants to merge 7 commits intomainfrom
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughReplaces Apollo GraphQL user lookups with Prisma Changes
Sequence Diagram(s)sequenceDiagram
participant Service as Email Service
participant Prisma as Prisma Users Client
participant Renderer as Template Renderer
participant Sender as Email Sender
Service->>Prisma: findUnique(userId) / findMany(userIds)
Prisma-->>Service: user record(s) (id, email, firstName, imageUrl)
Service->>Service: toEmailRecipient(user) → EmailRecipient
Service->>Renderer: renderTemplate(template, { recipient })
Renderer-->>Service: renderedHtml, subject
Service->>Sender: sendEmail(to=recipient.email, subject, html)
Sender-->>Service: sendResult
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
View your CI Pipeline Execution ↗ for commit ea5785d
☁️ Nx Cloud last updated this comment at |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
apis/api-journeys-modern/src/workers/email/service/service.spec.ts (1)
195-200: Add regression coverage for the new lookup edge cases.These specs only mock fully populated user rows. Please add cases for a
userIdlookup returningemail: nulland for the manager batch lookup returning fewer rows than requested, so the new recipient-resolution branches fail loudly instead of regressing silently.Also applies to: 273-288
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apis/api-journeys-modern/src/workers/email/service/service.spec.ts` around lines 195 - 200, Add two regression tests in service.spec.ts to exercise the recipient-resolution error branches: 1) Create a test that stubs mockPrismaUsers.user.findUnique (the userId lookup) to resolve to an object with email: null (and valid id/firstName) and assert the service throws or rejects with the expected error when resolving recipients for that userId; 2) Create a test that stubs mockPrismaUsers.user.findMany (the manager batch lookup used by the manager-resolution code path) to return fewer rows than the requested manager IDs and assert the service fails loudly (throws/rejects) rather than silently continuing. Use the same setup helpers/fixtures already present in the file and mirror existing test structure around mockPrismaUsers.user.findUnique and mockPrismaUsers.user.findMany so these new tests cover the two new edge branches referenced in recipient-resolution.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apis/api-journeys-modern/src/workers/email/service/service.ts`:
- Around line 59-66: The code is coercing null emails to an empty string when
building recipient objects (see recipientUser -> user creation), which allows
invalid recipients to proceed; update the logic to 1) define a shared
EmailRecipient type/helper and use it across the places mentioned (current block
and the similar blocks at the other ranges), 2) check recipientUser.email
explicitly and if it's null/undefined return or throw before any
rendering/sending or preference lookups, and 3) replace the current spread that
sets email: recipientUser.email ?? '' with construction that only creates an
EmailRecipient when email is present (and preserve lastName handling as
optional). Locate and update the recipient construction code paths referencing
recipientUser, ensure preference/delivery functions accept the typed
EmailRecipient only, and remove the empty-string normalization.
- Around line 221-230: The code currently builds recipients via
recipientUserIds.map(id => recipientUsersByUserId.get(id)) and only throws
inside the send loop, which can cause partial delivery; modify the logic in the
block around recipients, recipientUserIds and recipientUsersByUserId to validate
the entire batch before any sends by checking for any undefined entries (e.g.,
find missingIds = recipientUserIds.filter(id => !recipientUsersByUserId.has(id))
or check recipients.some(r => r == null)) and throw a clear error (including
missing ids) if any manager is absent so the subsequent send loop over
recipients only runs when all recipients are present.
---
Nitpick comments:
In `@apis/api-journeys-modern/src/workers/email/service/service.spec.ts`:
- Around line 195-200: Add two regression tests in service.spec.ts to exercise
the recipient-resolution error branches: 1) Create a test that stubs
mockPrismaUsers.user.findUnique (the userId lookup) to resolve to an object with
email: null (and valid id/firstName) and assert the service throws or rejects
with the expected error when resolving recipients for that userId; 2) Create a
test that stubs mockPrismaUsers.user.findMany (the manager batch lookup used by
the manager-resolution code path) to return fewer rows than the requested
manager IDs and assert the service fails loudly (throws/rejects) rather than
silently continuing. Use the same setup helpers/fixtures already present in the
file and mirror existing test structure around mockPrismaUsers.user.findUnique
and mockPrismaUsers.user.findMany so these new tests cover the two new edge
branches referenced in recipient-resolution.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 0ba6bdf0-7f1f-4cfb-9512-4e10d75f4115
📒 Files selected for processing (2)
apis/api-journeys-modern/src/workers/email/service/service.spec.tsapis/api-journeys-modern/src/workers/email/service/service.ts
- Introduced EmailRecipient interface for better type safety. - Added toEmailRecipient function to standardize user data transformation. - Updated service functions to utilize the new recipient handling logic, ensuring email addresses are validated before sending. - Enhanced error handling for cases where users lack email addresses.
|
I see you added the "on stage" label, I'll get this merged to the stage branch! |
|
Merge conflict attempting to merge this into stage. Please fix manually. |
…n email service
Summary by CodeRabbit
Bug Fixes
New Features
Tests