diff --git a/docs/api/routes/category/delete.md b/docs/api/routes/category/delete.md index 8667d3f..2252d9b 100644 --- a/docs/api/routes/category/delete.md +++ b/docs/api/routes/category/delete.md @@ -29,6 +29,8 @@ _No content_ | 400 | Invalid id or cannot delete root — `{"error":"…"}` | | 401 | Unauthorized — `{"error":"…"}` | | 403 | Not authorized — `{"error":"…"}` | +| 404 | Category not found — `{"error":"…"}` | +| 409 | Category has articles or subcategories — `{"error":"…"}` | --- diff --git a/src/api/routes/article.js b/src/api/routes/article.js index 198cd80..176fd80 100644 --- a/src/api/routes/article.js +++ b/src/api/routes/article.js @@ -54,7 +54,12 @@ function articleErrorStatus(error) { if (error.message === 'Unsupported image format' || error.message?.includes('unsupported image format')) return 400; if (error.message === 'Not authorized') return 403; if (error.message === 'Parent not found') return 404; - if (error.message === 'Article not found') return 404; + if ( + error.message === 'Article not found' || + error.message?.startsWith('Article not found') || + error.message?.startsWith('Component article not found') || + error.message?.startsWith('Option article not found') + ) return 404; if (error.message === 'Image not found') return 404; if (error.message === 'Name required') return 400; if (error.message === 'Invalid image order') return 400; @@ -86,13 +91,17 @@ function articleErrorStatus(error) { if (error.message === 'Father article not found') return 404; if ( error.message?.includes('Stückliste') || - error.message?.includes('options') || - error.message?.includes('option') || + error.message?.toLowerCase().includes('option') || + error.message?.includes('Item at index') || + error.message?.includes('Option at index') || error.message?.includes('Invalid items array') || error.message?.includes('Invalid options array') || error.message?.includes('Invalid count') || + error.message?.includes('Invalid sort') || + error.message?.includes('Invalid mandated') || error.message?.includes('circular') || - error.message?.includes('Circular') + error.message?.includes('Circular') || + error.message?.includes('Duplicate article') ) return 400; return 500; } diff --git a/src/api/routes/category.js b/src/api/routes/category.js index 54ec93c..3be3b16 100644 --- a/src/api/routes/category.js +++ b/src/api/routes/category.js @@ -34,6 +34,14 @@ function categoryErrorStatus(error) { if (error.message === 'Image not found') return 404; if (error.message === 'Invalid category order') return 400; if (error.message === 'Invalid parent') return 400; + if ( + error.message === 'Category has articles' || + error.message === 'Category has subcategories' || + error.message === 'Category is assigned to POS terminals' || + error.message?.includes('FOREIGN KEY constraint failed') || + error.message?.includes('foreign key constraint') || + error.message?.includes('REFERENCE constraint') + ) return 409; return 500; } @@ -519,6 +527,18 @@ export function register(app, basePath = '') { * application/json: * schema: * $ref: '#/components/schemas/Error' + * 404: + * description: Category not found + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' + * 409: + * description: Category has articles or subcategories + * content: + * application/json: + * schema: + * $ref: '#/components/schemas/Error' */ app.delete(`${basePath}/category/:id`, async (req, res) => { const parsed = parsePositiveInt(req.params.id, 'id');