diff --git a/docs/api/routes/stock/accept.md b/docs/api/routes/stock/accept.md index e35afe8..f182e84 100644 --- a/docs/api/routes/stock/accept.md +++ b/docs/api/routes/stock/accept.md @@ -45,9 +45,11 @@ Delivery item(s) accepted successfully | Status | Description | |--------|-------------| -| 400 | Validation error or no company selected | -| 404 | Manifest article or warehouse not found | -| 409 | Delivery line already accepted on ledger | +| 400 | Validation error or no company selected — `{"error":"…"}` | +| 401 | Unauthorized — `{"error":"…"}` | +| 403 | Not authorized — `{"error":"…"}` | +| 404 | Manifest article or warehouse not found — `{"error":"…"}` | +| 409 | Delivery line already accepted on ledger or stock tracking disabled — `{"error":"…"}` | --- diff --git a/docs/api/routes/stock/adjust.md b/docs/api/routes/stock/adjust.md index 1ff15f6..ec96773 100644 --- a/docs/api/routes/stock/adjust.md +++ b/docs/api/routes/stock/adjust.md @@ -92,6 +92,7 @@ Stock adjusted successfully | 401 | Unauthorized — `{"error":"…"}` | | 403 | Not authorized — `{"error":"…"}` | | 404 | Article or warehouse not found — `{"error":"…"}` | +| 409 | Stock tracking is disabled — `{"error":"…"}` | --- diff --git a/docs/api/routes/stock/ship.md b/docs/api/routes/stock/ship.md index 2b05758..6aa111b 100644 --- a/docs/api/routes/stock/ship.md +++ b/docs/api/routes/stock/ship.md @@ -45,9 +45,11 @@ Shipment item(s) shipped successfully | Status | Description | |--------|-------------| -| 400 | Validation error or no company selected | -| 404 | Manifest article or warehouse not found | -| 409 | Shipment line already shipped on ledger | +| 400 | Validation error or no company selected — `{"error":"…"}` | +| 401 | Unauthorized — `{"error":"…"}` | +| 403 | Not authorized — `{"error":"…"}` | +| 404 | Manifest article or warehouse not found — `{"error":"…"}` | +| 409 | Shipment line already shipped on ledger or stock tracking disabled — `{"error":"…"}` | --- diff --git a/src/api/routes/stock.js b/src/api/routes/stock.js index c447be9..10efd46 100644 --- a/src/api/routes/stock.js +++ b/src/api/routes/stock.js @@ -14,16 +14,29 @@ function requireSelectedCompany(req) { function stockErrorStatus(error) { if (error.message === 'No company selected') return 400; if (error.message === 'Not authorized') return 403; - if (error.message === 'Company not found') return 404; - if (error.message === 'Article not found') return 404; - if (error.message === 'Warehouse not found') return 404; - if (error.message?.includes('SKU required')) return 400; - if (error.message?.includes('Warehouse required')) return 400; - if (error.message?.includes('Amount must be')) return 400; - if (error.message?.includes('Invalid amount')) return 400; - if (error.message === 'No items to adjust') return 400; - if (error.message?.includes('cannot have stock') || error.message?.includes('A parent article cannot have') || error.message?.includes('parent article') || error.message?.includes('Stückliste')) return 400; - if (error.message?.includes('Stock tracking is disabled')) return 409; + if (error.message?.includes('not found')) return 404; + if ( + error.message?.includes('already accepted') || + error.message?.includes('already shipped') || + error.message?.includes('already booked') || + error.message?.includes('Stock tracking is disabled') + ) { + return 409; + } + if ( + error.message?.includes('required') || + error.message?.includes('Invalid') || + error.message?.includes('Amount must be') || + error.message?.includes('Warehouse must be') || + error.message?.includes('No items') || + error.message?.includes('does not belong to') || + error.message?.includes('cannot have stock') || + error.message?.includes('parent article') || + error.message?.includes('Stückliste') || + error.message?.includes('has no SKU') + ) { + return 400; + } return 500; } @@ -114,6 +127,12 @@ export function register(app, basePath = '') { * application/json: * schema: * $ref: '#/components/schemas/Error' + * 409: + * description: Stock tracking is disabled + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' */ // #region POST /stock/adjust @@ -178,10 +197,34 @@ export function register(app, basePath = '') { * description: Delivery item(s) accepted successfully * 400: * description: Validation error or no company selected + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * 401: + * description: Unauthorized + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * 403: + * description: Not authorized + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' * 404: * description: Manifest article or warehouse not found + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' * 409: - * description: Delivery line already accepted on ledger + * description: Delivery line already accepted on ledger or stock tracking disabled + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' */ // #region POST /stock/accept @@ -249,10 +292,34 @@ export function register(app, basePath = '') { * description: Shipment item(s) shipped successfully * 400: * description: Validation error or no company selected + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * 401: + * description: Unauthorized + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * 403: + * description: Not authorized + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' * 404: * description: Manifest article or warehouse not found + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' * 409: - * description: Shipment line already shipped on ledger + * description: Shipment line already shipped on ledger or stock tracking disabled + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' */ // #region POST /stock/ship