-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Skip /remap-default-links if no partners exist for a group
#2909
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
WalkthroughThe DELETE handler in apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts now computes partnerIds from group.partners and conditionally triggers the qstash remap-default-links call only when partnerIds.length > 0. The request body uses the partnerIds variable instead of inline mapping. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Client
participant API as DELETE /api/groups/:idOrSlug
participant DB as Database
participant QS as QStash (remap-default-links)
C->>API: DELETE group
API->>DB: Fetch group with partners
alt group found
API->>DB: Delete group
API->>API: Compute partnerIds = group.partners.map(id)
alt partnerIds.length > 0
API->>QS: POST remap-default-links { partnerIds }
QS-->>API: Ack
else No partners
Note over API: Skip remap request
end
API-->>C: 200 OK
else not found
API-->>C: 404 Not Found
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
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 |
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.
Actionable comments posted: 0
🧹 Nitpick comments (1)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts (1)
299-309: Conditional execution works but could be cleaner.The conditional qstash call successfully achieves the PR objective of skipping the remap when no partners exist. However, the use of
&&inside thePromise.allSettledarray results in afalsevalue when the condition isn't met, which is unconventional (though functional).For cleaner code, consider filtering the promises instead:
waitUntil( - Promise.allSettled([ - partnerIds.length > 0 && - qstash.publishJSON({ - url: `${APP_DOMAIN_WITH_NGROK}/api/cron/groups/remap-default-links`, - body: { - programId, - groupId: defaultGroup.id, - partnerIds, - userId: session.user.id, - isGroupDeleted: true, - }, - }), - - recordAuditLog({ + Promise.allSettled([ + ...(partnerIds.length > 0 + ? [ + qstash.publishJSON({ + url: `${APP_DOMAIN_WITH_NGROK}/api/cron/groups/remap-default-links`, + body: { + programId, + groupId: defaultGroup.id, + partnerIds, + userId: session.user.id, + isGroupDeleted: true, + }, + }), + ] + : []), + recordAuditLog({ workspaceId: workspace.id,Note: The PATCH handler (lines 182-188) uses the same
&&pattern, so this suggestion could apply there as well if you prefer consistency across the file.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts (1)
packages/utils/src/constants/main.ts (1)
APP_DOMAIN_WITH_NGROK(20-25)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts (1)
295-295: LGTM! Clean extraction of partner IDs.The extraction of
partnerIdsbefore thewaitUntilblock improves readability and avoids redundant computation.
Summary by CodeRabbit