-
Notifications
You must be signed in to change notification settings - Fork 14
Api delete pre-check #769
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
Api delete pre-check #769
Conversation
Co-authored-by: justin <[email protected]>
|
Cursor Agent can help with this pull request. Just |
📝 WalkthroughWalkthroughThe PR enhances deletion handlers across four resource types (deployments, environments, relationship-rules, and systems) by adding pre-fetch validation and populating deletion events with actual resource data instead of empty placeholder objects. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Handler as Delete Handler
participant APIClient as API Client
participant EventBus as Event Emitter
participant DB as Database
rect rgba(200, 150, 100, 0.5)
Note over Client,DB: Before: Direct deletion without pre-fetch
Client->>Handler: DELETE /resource/{id}
Handler->>EventBus: Emit deleted event (empty data)
Handler->>Client: 202/204 response
end
rect rgba(100, 150, 200, 0.5)
Note over Client,DB: After: Pre-fetch before deletion
Client->>Handler: DELETE /resource/{id}
Handler->>APIClient: GET /resource/{id}
APIClient->>DB: Query resource
DB-->>APIClient: Return resource data
APIClient-->>Handler: Return resource response
alt Resource found
Handler->>EventBus: Emit deleted event (real data)
Handler->>Client: 202/204 response
else Resource not found
Handler->>Client: 404 ApiError
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 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 |
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
apps/api/src/routes/v1/workspaces/deployments.ts (2)
139-139:⚠️ Potential issue | 🟡 MinorRemove debug
console.logstatement.This appears to be a leftover debug artifact that should not be committed.
🧹 Proposed fix
const { body } = req; - console.log(body); - const existingDeploymentResponse = await existingDeploymentById(
147-164:⚠️ Potential issue | 🟠 MajorMissing
resourceSelectorvalidation on the create path.When
deployment == null, aDeploymentCreatedevent is emitted without validating theresourceSelector. However,postDeployment(line 117-118) validates the selector before creating. This inconsistency could allow invalid selectors through the upsert-create path.🛡️ Proposed fix to add validation on the create path
if (deployment == null) { + const isValid = await validResourceSelector(body.resourceSelector); + if (!isValid) throw new ApiError("Invalid resource selector", 400); + await sendGoEvent({ workspaceId, eventType: Event.DeploymentCreated,
🧹 Nitpick comments (1)
apps/api/src/routes/v1/workspaces/systems.ts (1)
75-85: Consider consistent error handling pattern.The pre-fetch errors throw
ApiError(propagated byasyncHandler), butsendGoEventerrors are caught and return a generic 500. Other delete handlers in this PR let errors propagate naturally. Consider removing the try/catch for consistency and to preserve error details.♻️ Proposed refactor for consistent error handling
- try { - await sendGoEvent({ - workspaceId, - eventType: Event.SystemDeleted, - timestamp: Date.now(), - data: systemResponse.data.system, - }); - } catch { - res.status(500).json({ message: "Failed to delete system" }); - return; - } + await sendGoEvent({ + workspaceId, + eventType: Event.SystemDeleted, + timestamp: Date.now(), + data: systemResponse.data.system, + }); res.status(204).json({ message: "System deleted successfully" });
Add pre-delete existence checks for deployments, environments, relationship rules, and systems to ensure items exist before sending delete events and to use actual entity data in event payloads.
Note
Low Risk
Low risk: adds pre-delete fetches and reuses fetched data in delete events; behavior change is limited to returning proper 404s and emitting richer payloads for existing resources.
Overview
Adds pre-delete fetch/validation for
deployments,environments,relationship-rules, andsystemsdelete endpoints so missing resources return a proper not-found error instead of emitting a delete event.Updates delete event emission (
sendGoEvent) to use the real fetched entity payload (e.g.,deployment,environmentResponse.data,relationshipRuleResponse.data,systemResponse.data.system) rather than placeholder/empty fields.Written by Cursor Bugbot for commit db6f9ad. This will update automatically on new commits. Configure here.
Summary by CodeRabbit
Bug Fixes
✏️ Tip: You can customize this high-level summary in your review settings.