WIP: feat(api): endpoint for posibility of connections for ERP systems - #204
Open
JanKolo04 wants to merge 2 commits into
Open
WIP: feat(api): endpoint for posibility of connections for ERP systems#204JanKolo04 wants to merge 2 commits into
JanKolo04 wants to merge 2 commits into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ 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 |
Contributor
|
@JanKolo04 conflicts |
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.
Summary
Adds a standardized, ERP-agnostic REST API under
/api/v1/erp/*for synchronizing with external ERPs (SAP, Comarch,enova365, Microsoft Dynamics / Business Central). One canonical JSON contract; per-ERP field-mapping connectors are a documented
follow-up.
enova365, Microsoft Dynamics / Business Central). One canonical JSON contract; per-ERP field-mapping connectors are a documented
follow-up.
Endpoints
POST /erp/work-orders/import— bulk import work orders (canonical JSON). Reuses the existingWorkOrderImportService, soCSV and ERP share one create/validate path. Orders resolve line + product type by code. A malformed payload is rejected
wholesale (
422); a bad reference in one order does not fail the batch — a well-formed batch always returns a per-orderreport,
207 Multi-Statuswhen some rows errored, each carrying{row, field, message}.GET /erp/production/completions— produced quantities + completion timestamps per work order.GET /erp/quality/issues— non-conformance / issue reports.GET /erp/work-orders/{id}— single-order state confirmation.Exports are cursor-paginated with a
sincefilter for incremental polling.Auth & limits
X-Api-KeyorAuthorization: Bearer) with configurable per-endpoint scopes(
erp:orders:import,erp:production:read,erp:quality:read), optional IP allowlist and expiry. Only the SHA-256hash of the secret is stored; the plaintext is shown once at creation.
role:Admin, API CRUD; a React admin page is a follow-up).erp-import(30/min) throttled tighter thanerp-read(120/min).Tenant isolation for headless requests
ERP requests carry no logged-in user, so a new request-scoped
TenantContextfeeds the existingTenantScope/HasTenantas a fallback — every ERP query stays correctly tenant-scoped. Change is backward-compatible (the user-auth path is unchanged).
Issuehas notenant_id, so it's isolated through its work order (whereHas('workOrder')).Feasibility validated — all four ERP families can integrate with this contract (SAP via ABAP/CPI, enova365 via a C# add-on,
Dynamics BC via
api/v2.0/AL, Comarch via a .NET connector). Two follow-ups surfaced: OAuth2 client-credentials (for SAP/MScloud) alongside the API key, and a
production.completedwebhook (push for cloud ERPs that can't reach an on-prem endpoint).Type of change
Related issue
Closes #
Testing
Added 17 feature tests (
tests/Feature/Api/V1/Erp/*,ApiKeyManagementTest) covering the happy path,422malformed payload,207partial import with structured row errors,401(missing/invalid/expired key),403(missing scope), per-tenantisolation on both exports, and one-time plaintext exposure on key creation. Ran alongside existing tenant-isolation and
CSV-import suites — no regressions.
php artisan testpassesChecklist
.envsecrets committed$fillableupdated if new model columns addedcomposer auditclean