This commit is contained in:
seb
2026-10-20 23:21:48 +02:00
parent 5a5981dc07
commit b7058df5d2
16 changed files with 345 additions and 1063 deletions

View File

@@ -74,15 +74,8 @@ export function register(app, basePath = '') {
* taxRate: 19
* minmultiplier: 10
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Invalid prices, POS customer group required, or parent article cannot have prices
* content:
@@ -121,9 +114,9 @@ export function register(app, basePath = '') {
}
try {
const article = await db.setPricesBySku(req.user.id, skuParsed.sku, req.body.prices);
await db.setPricesBySku(req.user.id, skuParsed.sku, req.body.prices);
emitArticleSignal(req, skuParsed.sku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Set article prices failed:', error);
@@ -167,15 +160,8 @@ export function register(app, basePath = '') {
* example:
* eans: ["4001234567890"]
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Invalid eans
* content:
@@ -220,9 +206,9 @@ export function register(app, basePath = '') {
}
try {
const article = await db.setEansBySku(req.user.id, skuParsed.sku, req.body.eans);
await db.setEansBySku(req.user.id, skuParsed.sku, req.body.eans);
emitArticleSignal(req, skuParsed.sku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Set article eans failed:', error);
@@ -266,15 +252,8 @@ export function register(app, basePath = '') {
* example:
* brandId: 3
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Validation error
* content:
@@ -314,9 +293,9 @@ export function register(app, basePath = '') {
}
try {
const article = await db.setBrandIdBySku(req.user.id, skuParsed.sku, brandId);
await db.setBrandIdBySku(req.user.id, skuParsed.sku, brandId);
emitArticleSignal(req, skuParsed.sku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Set article brand failed:', error);
@@ -358,15 +337,8 @@ export function register(app, basePath = '') {
* example:
* weight: 1.5
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Invalid weight
* content:
@@ -403,9 +375,9 @@ export function register(app, basePath = '') {
const weight = req.body?.weight;
try {
const article = await db.setWeightBySku(req.user.id, skuParsed.sku, weight);
await db.setWeightBySku(req.user.id, skuParsed.sku, weight);
emitArticleSignal(req, skuParsed.sku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Set article weight failed:', error);
@@ -449,15 +421,8 @@ export function register(app, basePath = '') {
* example:
* track_stock: true
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Invalid track_stock
* content:
@@ -497,9 +462,9 @@ export function register(app, basePath = '') {
}
try {
const article = await db.setTrackStockBySku(req.user.id, skuParsed.sku, Boolean(raw));
await db.setTrackStockBySku(req.user.id, skuParsed.sku, Boolean(raw));
emitArticleSignal(req, skuParsed.sku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Set article track_stock failed:', error);
@@ -548,15 +513,8 @@ export function register(app, basePath = '') {
* example:
* categoryIds: [4, 7]
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Invalid categoryIds or empty array
* content:
@@ -595,13 +553,13 @@ export function register(app, basePath = '') {
}
try {
const article = await db.setCategoryIdsBySku(
await db.setCategoryIdsBySku(
req.user.id,
skuParsed.sku,
req.body.categoryIds,
);
emitArticleSignal(req, skuParsed.sku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Set article categories failed:', error);

View File

@@ -64,8 +64,8 @@ export function register(app, basePath = '') {
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleSummary'
* sku:
* type: string
* 400:
* description: Validation error
* content:
@@ -133,11 +133,7 @@ export function register(app, basePath = '') {
seo: req.body?.seo !== undefined ? req.body.seo : undefined,
});
emitArticlesSignal(req);
const article = {
...created,
categoryId: created.parentId,
};
res.status(201).json({ article });
res.status(201).json({ sku: created.sku });
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Create article failed:', error);
@@ -501,15 +497,8 @@ export function register(app, basePath = '') {
* unitamount: 0.24
* unitSi: l
* responses:
* 200:
* description: Updated article detail
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/ArticleDetail'
* 204:
* description: Updated
* 400:
* description: Validation error (Name required / Invalid unitamount)
* content:
@@ -753,10 +742,10 @@ export function register(app, basePath = '') {
try {
const decodedSku = decodeURIComponent(sku);
const article = await db.updateBySku(req.user.id, decodedSku, patch);
await db.updateBySku(req.user.id, decodedSku, patch);
emitArticlesSignal(req);
emitArticleSignal(req, decodedSku);
res.status(200).json({ article });
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Update article by sku failed:', error);

View File

@@ -56,15 +56,8 @@ export function register(app, basePath = '') {
* The attributename id used for the article's variants. Omitting it while
* enabling parent mode returns 400. Must be omitted when `isParent` is `false`.
* responses:
* 200:
* description: Updated article
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/Article'
* 204:
* description: Updated
* 400:
* description: |
* Invalid input — `attributeNameId` missing while `isParent` is true, article still
@@ -89,13 +82,13 @@ export function register(app, basePath = '') {
const attributeNameId = req.body?.attributeNameId;
try {
const result = await db.toggleParent(req.user.id, parsed.sku, {
await db.toggleParent(req.user.id, parsed.sku, {
isParent,
attributeNameId,
});
emitArticleSignal(req, parsed.sku);
emitArticlesSignal(req);
res.status(200).json(result);
res.status(204).end();
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Toggle parent failed:', error);
@@ -196,8 +189,8 @@ export function register(app, basePath = '') {
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/Article'
* sku:
* type: string
* 400:
* description: Parent not configured as parent, missing value, duplicate variant, or sku was provided in body
* put:
@@ -237,14 +230,12 @@ export function register(app, basePath = '') {
* description: Whether to allow re-parenting if child already belongs to another parent
* responses:
* 200:
* description: Attached child article and list of children
* description: List of children after attaching
* content:
* application/json:
* schema:
* type: object
* properties:
* article:
* $ref: '#/components/schemas/Article'
* children:
* type: array
* items:
@@ -275,7 +266,7 @@ export function register(app, basePath = '') {
emitArticleSignal(req, result.article.sku);
}
emitArticlesSignal(req);
res.status(201).json(result);
res.status(201).json({ sku: result.article.sku });
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Add child failed:', error);
@@ -303,7 +294,7 @@ export function register(app, basePath = '') {
emitArticleSignal(req, parsed.sku);
emitArticleSignal(req, childSku);
emitArticlesSignal(req);
res.status(200).json(result);
res.status(200).json({ children: result.children });
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Attach child failed:', error);