This commit is contained in:
seb
2026-09-30 23:11:01 +02:00
parent 120e59631e
commit 956fadcc8d
3 changed files with 35 additions and 4 deletions

View File

@@ -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');