[MAIN-IMP] Add endpoints to get and set proxies directly on a job#103
[MAIN-IMP] Add endpoints to get and set proxies directly on a job#103moda20 wants to merge 3 commits into
Conversation
…tly (instead of adding multip jobs to a single proxy)
|
Warning Review limit reached
More reviews will be available in 14 minutes and 42 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (6)
📒 Files selected for processing (3)
📝 WalkthroughWalkthroughTwo new API endpoints are added to the proxies controller: ChangesBulk proxy-job association
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/api/proxies/proxies.controller.ts`:
- Around line 135-146: In the body validation schema for the addProxiesToJob
endpoint, update the job_id field to include .positive() and .int() after
z.coerce.number() to ensure it validates as a positive integer, consistent with
database ID requirements. Additionally, add .int() to the proxy_ids array
element validation after .positive() to ensure proxy IDs are also validated as
positive integers, matching the complete validation pattern demonstrated in the
/testProxy endpoint at line 167.
- Around line 56-67: The getJobProxies endpoint lacks proper query validation
and error handling. First, add a query validation schema for the jobId parameter
(using the same pattern as other endpoints in the file) to ensure it's a valid
number and reject invalid, missing, or array values. Second, when getJobProxies
returns null for a missing job, the optional chaining expression
data?.proxies?.map(...) returns undefined instead of a proper response. Fix this
by adding a nullish coalescing operator (??) with an empty array as fallback, so
that clients receive an empty array instead of undefined when a job is not
found.
In `@src/repositories/proxies.ts`:
- Around line 193-224: The `addProxiesToJob` function has a race condition where
concurrent requests can compute identical `linksToCreate` arrays and both
attempt to insert the same proxy_job records, causing duplicates since no unique
constraint exists on the (job_id, proxy_id) pair. Fix this by either: (1) adding
`@@unique([job_id, proxy_id])` to the `proxy_job` model in the Prisma schema
file, or (2) modifying the `createMany` call in the transaction to use
`skipDuplicates: true` option to safely ignore duplicate inserts. Either
approach prevents duplicate records when concurrent requests target the same
job.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 20481bc1-c650-4cf7-ad4c-b03193b51677
📒 Files selected for processing (2)
src/api/proxies/proxies.controller.tssrc/repositories/proxies.ts
adding unique constraint to proxy_job to disallow duplicated references
Improvements:
/getJobProxiesand/addProxiesToJobendpoints to retrieve all Job linked proxies and save the links with links diff only prisma transactionNotes
any notes, opinions, mention, impact :
How Has This Been Tested?
Related Issues
Screenshots (if applicable)
Additional Context