u
This commit is contained in:
@@ -18,6 +18,8 @@ function orderErrorStatus(error) {
|
||||
if (error.message === 'Invalid entityId') return 400;
|
||||
if (error.message === 'Invalid order') return 400;
|
||||
if (error.message === 'Invalid lines') return 400;
|
||||
if (error.message === 'Invalid offset') return 400;
|
||||
if (error.message === 'Invalid limit') return 400;
|
||||
if (error.message?.includes('parent article') || error.message?.includes('A parent article')) return 400;
|
||||
return 500;
|
||||
}
|
||||
@@ -37,8 +39,25 @@ export function register(app, basePath = '') {
|
||||
* description: |
|
||||
* Lists sales orders (`manifest` rows with `type = 'order'`)
|
||||
* for the authenticated user's selected company.
|
||||
* Results are paged, include line items, and provide total unpaged count.
|
||||
* security:
|
||||
* - cookieAuth: []
|
||||
* parameters:
|
||||
* - in: query
|
||||
* name: offset
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 0
|
||||
* minimum: 0
|
||||
* description: Number of orders to skip
|
||||
* - in: query
|
||||
* name: limit
|
||||
* schema:
|
||||
* type: integer
|
||||
* default: 20
|
||||
* minimum: 1
|
||||
* maximum: 100
|
||||
* description: Number of orders to return
|
||||
* x-markdown: order/list.md
|
||||
* responses:
|
||||
* 200:
|
||||
@@ -47,13 +66,23 @@ export function register(app, basePath = '') {
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required: [orders, total, offset, limit]
|
||||
* properties:
|
||||
* orders:
|
||||
* type: array
|
||||
* items:
|
||||
* $ref: '#/components/schemas/OrderSummary'
|
||||
* $ref: '#/components/schemas/Order'
|
||||
* total:
|
||||
* type: integer
|
||||
* description: Total number of unpaged orders
|
||||
* offset:
|
||||
* type: integer
|
||||
* description: Number of orders skipped
|
||||
* limit:
|
||||
* type: integer
|
||||
* description: Number of orders returned
|
||||
* 400:
|
||||
* description: No company selected
|
||||
* description: Invalid offset, invalid limit, or no company selected
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
@@ -161,9 +190,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 = 20;
|
||||
|
||||
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 orders = await db.list(req.user.id);
|
||||
res.status(200).json({ orders });
|
||||
const result = await db.list(req.user.id, { offset, limit });
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
const status = orderErrorStatus(error);
|
||||
if (status === 500) console.error('List orders failed:', error);
|
||||
|
||||
Reference in New Issue
Block a user