This commit is contained in:
seb
2026-09-30 19:29:13 +02:00
parent d6fe6ff1d2
commit e358eccca9
80 changed files with 1185 additions and 225 deletions

View File

@@ -111,7 +111,7 @@ export function register(app, basePath = '') {
* /article:
* post:
* tags: [Article]
* summary: Create article
* summary: Create article in category
* description: Creates an article under an authorized category (`parentId`).
* security:
* - cookieAuth: []
@@ -123,18 +123,18 @@ export function register(app, basePath = '') {
* application/json:
* schema:
* type: object
* required: [parentId, name]
* required: [categoryId, name]
* properties:
* parentId:
* categoryId:
* type: integer
* description: Category id
* description: Category ID under which to create the article
* name:
* type: string
* track_stock:
* type: boolean
* description: Whether to track inventory stock (defaults to true)
* example:
* parentId: 10
* categoryId: 10
* name: New article
* responses:
* 201:
@@ -178,7 +178,7 @@ export function register(app, basePath = '') {
* $ref: '#/components/schemas/Error'
*/
app.post(`${basePath}/article`, async (req, res) => {
const parent = parsePositiveInt(req.body?.parentId, 'parentId');
const parent = parsePositiveInt(req.body?.categoryId ?? req.body?.parentId, 'categoryId');
if (parent.error) {
return res.status(400).json({ error: parent.error });
}
@@ -195,13 +195,17 @@ export function register(app, basePath = '') {
const track_stock = rawTrack !== undefined ? Boolean(rawTrack) : true;
try {
const article = await db.createUnderParent({
const created = await db.createUnderParent({
googleAuthId: req.user.id,
parentId: parent.id,
name,
track_stock,
});
emitArticlesSignal(req);
const article = {
...created,
categoryId: created.parentId,
};
res.status(201).json({ article });
} catch (error) {
const status = articleErrorStatus(error);