u
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user