u
This commit is contained in:
@@ -343,12 +343,8 @@
|
||||
* $ref: '#/components/schemas/SupplierArticleInfo'
|
||||
* BrandPic:
|
||||
* type: object
|
||||
* required: [id, sort, fullHash, thumbW, thumbH, thumbHash]
|
||||
* required: [fullHash, thumbW, thumbH, thumbHash]
|
||||
* properties:
|
||||
* id:
|
||||
* type: integer
|
||||
* sort:
|
||||
* type: integer
|
||||
* fullHash:
|
||||
* type: string
|
||||
* thumbW:
|
||||
|
||||
@@ -19,6 +19,8 @@ function brandErrorStatus(error) {
|
||||
if (error.message === 'Company not found') return 404;
|
||||
if (error.message === 'Brand not found') return 404;
|
||||
if (error.message === 'Invalid brand') return 400;
|
||||
if (error.message === 'Invalid offset') return 400;
|
||||
if (error.message === 'Invalid limit') return 400;
|
||||
if (error.message === 'Brand already exists') return 409;
|
||||
if (error.message === 'Brand in use') return 409;
|
||||
if (error.message === 'Image not found') return 404;
|
||||
@@ -45,9 +47,25 @@ export function register(app, basePath = '') {
|
||||
* get:
|
||||
* tags: [Brand]
|
||||
* summary: List brands
|
||||
* description: Lists brands for the authenticated user's selected company, sorted by name.
|
||||
* description: Lists brands for the authenticated user's selected company, sorted by name. Paged; `total` is the unpaged count.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: offset
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 0
|
||||
* minimum: 0
|
||||
* description: Number of brands to skip
|
||||
* - in: query
|
||||
* name: limit
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 10
|
||||
* minimum: 1
|
||||
* maximum: 100
|
||||
* description: Number of brands to return
|
||||
* x-markdown: brand/list.md
|
||||
* responses:
|
||||
* 200:
|
||||
@@ -56,13 +74,23 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [brands, total, offset, limit]
|
||||
* properties:
|
||||
* brands:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/Brand'
|
||||
* total:
|
||||
* type: integer
|
||||
* description: Total number of unpaged brands
|
||||
* offset:
|
||||
* type: integer
|
||||
* description: Number of brands skipped
|
||||
* limit:
|
||||
* type: integer
|
||||
* description: Number of brands returned
|
||||
* 400:
|
||||
* description: No company selected
|
||||
* description: Invalid offset, invalid limit, or no company selected
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
@@ -92,9 +120,29 @@ export function register(app, basePath = '') {
|
||||
return res.status(400).json({ error: selected.error });
|
||||
}
|
||||
|
||||
const rawOffset = req.query.offset;
|
||||
const rawLimit = req.query.limit;
|
||||
|
||||
let offset = 0;
|
||||
let limit = 10;
|
||||
|
||||
if (rawOffset !== undefined) {
|
||||
offset = parseInt(rawOffset, 10);
|
||||
if (!Number.isInteger(offset) || offset < 0) {
|
||||
return res.status(400).json({ error: 'offset must be an integer >= 0' });
|
||||
}
|
||||
}
|
||||
|
||||
if (rawLimit !== undefined) {
|
||||
limit = parseInt(rawLimit, 10);
|
||||
if (!Number.isInteger(limit) || limit < 1 || limit > 100) {
|
||||
return res.status(400).json({ error: 'limit must be an integer between 1 and 100' });
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const brands = await db.list(req.user.id);
|
||||
res.status(200).json({ brands });
|
||||
const result = await db.list(req.user.id, { offset, limit });
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = brandErrorStatus(error);
|
||||
if (status === 500) console.error('List brands failed:', error);
|
||||
|
||||
Reference in New Issue
Block a user