Skip to content

[MAIN-IMP] Add endpoints to get and set proxies directly on a job#103

Open
moda20 wants to merge 3 commits into
masterfrom
improvement/adding-job-to-proxies-link-endpoint
Open

[MAIN-IMP] Add endpoints to get and set proxies directly on a job#103
moda20 wants to merge 3 commits into
masterfrom
improvement/adding-job-to-proxies-link-endpoint

Conversation

@moda20

@moda20 moda20 commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Improvements:

  • [Improvement] : Added GET /getJobProxies and /addProxiesToJob endpoints to retrieve all Job linked proxies and save the links with links diff only prisma transaction

Notes

any notes, opinions, mention, impact :

  • [Note] : This allows to add proxies to a single job instead of only the other way around

How Has This Been Tested?

Related Issues

Screenshots (if applicable)

Additional Context

…tly (instead of adding multip jobs to a single proxy)
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@moda20, we couldn't start this review because you've reached your PR review rate limit.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6cd8f2c6-b0f6-4bd6-a25b-cbed843ff65e

📥 Commits

Reviewing files that changed from the base of the PR and between efb7359 and 580f317.

⛔ Files ignored due to path filters (6)
  • src/generated/prisma/edge.js is excluded by !**/generated/**
  • src/generated/prisma/index.d.ts is excluded by !**/generated/**
  • src/generated/prisma/index.js is excluded by !**/generated/**
  • src/generated/prisma/package.json is excluded by !**/generated/**
  • src/generated/prisma/schema.prisma is excluded by !**/generated/**
  • src/generated/prisma/wasm.js is excluded by !**/generated/**
📒 Files selected for processing (3)
  • prisma/migrations/20260614170009_adding_uniqueness_constraint_to_proxy_job/migration.sql
  • prisma/schema.prisma
  • src/api/proxies/proxies.controller.ts
📝 Walkthrough

Walkthrough

Two new API endpoints are added to the proxies controller: GET /getJobProxies retrieves proxies for a job mapped to connection fields, and POST /addProxiesToJob bulk-syncs proxy-job associations using zod validation. A new repository function addProxiesToJob handles the sync via a Prisma transaction with createMany and deleteMany.

Changes

Bulk proxy-job association

Layer / File(s) Summary
addProxiesToJob repository function
src/repositories/proxies.ts
Adds addProxiesToJob(jobId, proxyIds) which fetches existing proxy_job rows for the job, computes additions and removals by diffing against the provided IDs, and applies both in a single Prisma $transaction using createMany and deleteMany.
Controller imports and new routes
src/api/proxies/proxies.controller.ts
Extends the repository import to include addProxiesToJob and getJobProxies. Adds GET /getJobProxies returning a pared-down proxy array (id, proxy_id, proxy_ip, proxy_port), and POST /addProxiesToJob with zod coercion on job_id and positive-integer validation on proxy_ids.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐇 Hop, hop, one proxy won't do,
Now bulk-sync the whole bunny crew!
A transaction so neat, delete and create,
The join table stays tidy — oh, isn't that great?
Zod guards the door, only ints may pass through. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding endpoints for managing proxies on jobs, which aligns with the core implementation of two new API endpoints.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch improvement/adding-job-to-proxies-link-endpoint

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between a15404d and efb7359.

📒 Files selected for processing (2)
  • src/api/proxies/proxies.controller.ts
  • src/repositories/proxies.ts

Comment thread src/api/proxies/proxies.controller.ts Outdated
Comment thread src/api/proxies/proxies.controller.ts
Comment thread src/repositories/proxies.ts
moda20 added 2 commits June 14, 2026 18:01
adding unique constraint to proxy_job to disallow duplicated references
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.

1 participant