diff --git a/docs/api/routes/article/set-categories.md b/docs/api/routes/article/set-categories.md index 269a1ad..a21a064 100644 --- a/docs/api/routes/article/set-categories.md +++ b/docs/api/routes/article/set-categories.md @@ -5,8 +5,8 @@ Protected. Requires a valid session cookie (`credentials: 'include'`). Replace article categories by SKU Replace-all the article's category list. Each category must belong to -the article's company; ids must be unique. Empty array removes the -article from all categories. Returns the same shape as GET by SKU. +the article's company; ids must be unique. The article must belong to +at least one category (empty array is rejected). Returns the same shape as GET by SKU. ## Path parameters @@ -115,7 +115,7 @@ Updated article detail | Status | Description | |--------|-------------| -| 400 | Invalid categoryIds — `{"error":"…"}` | +| 400 | Invalid categoryIds or empty array — `{"error":"…"}` | | 401 | Unauthorized — `{"error":"…"}` | | 403 | Not authorized — `{"error":"…"}` | | 404 | Article not found — `{"error":"…"}` | diff --git a/src/api/routes/article.js b/src/api/routes/article.js index 7ff414e..da72d78 100644 --- a/src/api/routes/article.js +++ b/src/api/routes/article.js @@ -77,7 +77,7 @@ function articleErrorStatus(error) { if (error.message === 'Invalid attributeValueId') return 400; if (error.message === 'Invalid weight') return 400; if (error.message === 'Invalid track_stock') return 400; - if (error.message === 'Invalid categoryIds') return 400; + if (error.message === 'Invalid categoryIds' || error.message === 'Article must have at least one category') return 400; if (error.message === 'Attribute name not found') return 404; if (error.message === 'attributeNameId is required to become a parent article') return 400; if (error.message?.includes('already used by an ancestor parent')) return 400; @@ -1470,8 +1470,8 @@ export function register(app, basePath = '') { * summary: Replace article categories by SKU * description: | * Replace-all the article's category list. Each category must belong to - * the article's company; ids must be unique. Empty array removes the - * article from all categories. Returns the same shape as GET by SKU. + * the article's company; ids must be unique. The article must belong to + * at least one category (empty array is rejected). Returns the same shape as GET by SKU. * security: * - cookieAuth: [] * x-signals: [article-] @@ -1492,6 +1492,7 @@ export function register(app, basePath = '') { * properties: * categoryIds: * type: array + * minItems: 1 * items: * type: integer * example: @@ -1507,7 +1508,7 @@ export function register(app, basePath = '') { * article: * $ref: '#/components/schemas/ArticleDetail' * 400: - * description: Invalid categoryIds + * description: Invalid categoryIds or empty array * content: * application/json: * schema: