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

@@ -31,6 +31,7 @@ Generated from `@openapi` annotations in [`src/api/routes/`](../../src/api/route
| File | Endpoint |
|------|----------|
| [`routes/article/create.md`](routes/article/create.md) | `POST /article` |
| [`routes/article/delete.md`](routes/article/delete.md) | `DELETE /article/{sku}` |
| [`routes/article/get.md`](routes/article/get.md) | `GET /article/{sku}` |
| [`routes/article/update.md`](routes/article/update.md) | `PATCH /article/{sku}` |
| [`routes/article/add-image.md`](routes/article/add-image.md) | `POST /article/{sku}/image` |

View File

@@ -1206,6 +1206,75 @@
}
}
}
},
"delete": {
"tags": [
"Article"
],
"summary": "Delete article by SKU",
"description": "Deletes the article when it has no child articles. Cascades related rows;\nnulls `manifestarticle.article_id` and appends a delete comment.\nAuth like GET by SKU.\n",
"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"
}
}
}
}
}
}
},
"/article/{sku}/image": {

View File

@@ -0,0 +1,35 @@
# `DELETE /article/{sku}`
Protected. Requires a valid session cookie (`credentials: 'include'`).
Delete article by SKU
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.
## Path parameters
| Param | Required | Type | Description |
|-------|----------|------|-------------|
| `sku` | yes | string | Article SKU |
## Response `204`
Deleted
_No content_
## Errors
| Status | Description |
|--------|-------------|
| 400 | Article has children — `{"error":"…"}` |
| 401 | Unauthorized — `{"error":"…"}` |
| 403 | Not authorized — `{"error":"…"}` |
| 404 | Article not found — `{"error":"…"}` |
---
_Generated from `@openapi` JSDoc. Do not edit by hand — run `npm run docs:api`._

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:

View File

@@ -29,3 +29,8 @@ export async function orderImages(googleAuthId, sku, data) {
const store = await getStore();
return store.article.orderImages(googleAuthId, sku, data);
}
export async function remove(googleAuthId, sku) {
const store = await getStore();
return store.article.delete(googleAuthId, sku);
}