feat(api): bulk-create endpoints for 7 indirect-scoped entities (P3-H2)#88
Merged
Conversation
Follow-up to P3-H. The bulk surface was previously limited to the 5 entities with a direct *CompId column. This PR extends it to the remaining 7 soft-deletable entities, whose auth scope is resolved *through* a parent FK rather than carried directly: Customer-scoped (parent → Customer.custCompId): - POST /v1/job/bulk jobCustId - POST /v1/invoice/bulk invCustId - POST /v1/customerpayment/bulk cpayCustId Job-scoped (parent → Job → Customer.custCompId): - POST /v1/invoicejob/bulk injbJobId - POST /v1/productentry/bulk pentJobId Vendor/header-scoped: - POST /v1/purchaseorderheader/bulk pohPovId → vendor.povCompId - POST /v1/purchaseorderline/bulk polpoh → header → vendor Mechanics: - New factory `makeBulkCreateIndirect` in `app/controllers/_bulk-helpers.js` parameterizes over `parentFkField` + `resolveParentCompanyId(parentId)`. The 7 controllers gain ~10 LOC each instead of ~120. - Per-entry validation: parent FK is REQUIRED on every entry. For non-master keys the resolved parent company must equal the caller's company (else 403 with the offending index); master keys aren't pinned to a company so any resolved parent is fine. - Same 500-entry cap and transactional all-or-nothing insert as the direct family. Together with P3-H, the bulk surface now covers all 13 soft- deletable entities. Tests - `tests/api/bulk-indirect-scope.test.js`: 49 cases (7 entities x 7 assertions). Auth contract, outer-field 400s, empty/501-cap 400s, unknown-field 400, missing-parent-FK 400, route mounting. - Full suite: 469 pass / 4 skip (was 420/4 — +49 net new tests). - Lint clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #81 (P3-H). Extends bulk-create to the 7 entities scoped through a parent FK.
Summary
jobCustId)invCustId)cpayCustId)injbJobId)pentJobId)pohPovId)polpoh)makeBulkCreateIndirectfactory parameterizes over the parent FK + the auth-helper that resolves it.Test plan
tests/api/bulk-indirect-scope.test.js(49 cases): auth contract, outer-field/empty/501-cap/unknown-field/missing-parent-FK 400s, route mounting.This code proudly made in Nebraska. GO BIG RED! 🌽 https://xkcd.com/2347/