u
This commit is contained in:
@@ -324,7 +324,7 @@ export function register(app, basePath = '') {
|
||||
* get:
|
||||
* tags: [Category]
|
||||
* summary: Articles in category
|
||||
* description: Returns articles in a category the user is authorized for (omits child articles of a parent article), sorted alphabetically by name. Each article includes `childCount` (the number of its child articles) and small thumbnail fields (`smallThumbW`, `smallThumbH`, `smallThumbBinary`).
|
||||
* description: Returns articles in a category the user is authorized for, sorted alphabetically by name. By default includes child articles (variants); pass `includeChildren=false` to omit them. Each article includes `childCount` (the number of its child articles) and small thumbnail fields (`smallThumbW`, `smallThumbH`, `smallThumbBinary`).
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* x-markdown: category/articles.md
|
||||
@@ -335,6 +335,13 @@ export function register(app, basePath = '') {
|
||||
* schema:
|
||||
* type: integer
|
||||
* description: Category id
|
||||
* - in: query
|
||||
* name: includeChildren
|
||||
* required: false
|
||||
* schema:
|
||||
* type: boolean
|
||||
* default: true
|
||||
* description: When true (default), includes child articles (variants) alongside parent articles. Set to false to omit child articles.
|
||||
* responses:
|
||||
* 200:
|
||||
* description: Articles list
|
||||
@@ -374,10 +381,17 @@ export function register(app, basePath = '') {
|
||||
return res.status(400).json({ error: parsed.error });
|
||||
}
|
||||
|
||||
let includeChildren = true;
|
||||
if (req.query.includeChildren !== undefined) {
|
||||
includeChildren = req.query.includeChildren !== 'false' && req.query.includeChildren !== '0';
|
||||
} else if (req.query.variants !== undefined) {
|
||||
includeChildren = req.query.variants !== 'false' && req.query.variants !== '0';
|
||||
}
|
||||
|
||||
try {
|
||||
const allArticles = await db.getCategoryArticles(req.user.id, parsed.id);
|
||||
const articles = allArticles
|
||||
.filter((a) => a.parentArticleId == null)
|
||||
.filter((a) => includeChildren || a.parentArticleId == null)
|
||||
.map((a) => ({
|
||||
...a,
|
||||
childCount: Number(a.childCount ?? 0),
|
||||
|
||||
Reference in New Issue
Block a user