This commit is contained in:
seb
2026-08-01 03:39:10 +02:00
parent eaee806569
commit e8d8846de7
5 changed files with 171 additions and 0 deletions

View File

@@ -33,6 +33,7 @@ function articleErrorStatus(error) {
if (error.message === 'Image not found') return 404;
if (error.message === 'Name required') return 400;
if (error.message === 'Invalid image order') return 400;
if (error.message === 'Article has children') return 400;
return 500;
}
@@ -239,6 +240,50 @@ export function register(app, basePath = '') {
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
* delete:
* tags: [Article]
* summary: Delete article by SKU
* description: |
* Deletes the article when it has no child articles. Cascades related rows;
* nulls `manifestarticle.article_id` and appends a delete comment.
* Auth like GET by SKU.
* security:
* - cookieAuth: []
* x-markdown: article/delete.md
* parameters:
* - in: path
* name: sku
* required: true
* schema:
* type: string
* description: Article SKU
* responses:
* 204:
* description: Deleted
* 400:
* description: Article has children
* 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: Article not found
* content:
* application/json:
* schema:
* $ref: '#/components/schemas/Error'
*/
app.get(`${basePath}/article/:sku`, async (req, res) => {
const sku = typeof req.params.sku === 'string' ? req.params.sku.trim() : '';
@@ -277,6 +322,22 @@ export function register(app, basePath = '') {
}
});
app.delete(`${basePath}/article/:sku`, async (req, res) => {
const parsed = parseSku(req.params.sku);
if (parsed.error) {
return res.status(400).json({ error: parsed.error });
}
try {
await db.remove(req.user.id, parsed.sku);
res.sendStatus(204);
} catch (error) {
const status = articleErrorStatus(error);
if (status === 500) console.error('Delete article failed:', error);
res.status(status).json({ error: error.message });
}
});
/**
* @openapi
* /article/{sku}/image: