This commit is contained in:
seb
2026-10-14 13:31:25 +02:00
parent 80450e8748
commit 5fb8df6f6a
10 changed files with 240 additions and 56 deletions

View File

@@ -965,6 +965,18 @@
* createdAt:
* type: string
* format: date-time
* positions:
* type: integer
* description: Number of line items
* grossTotal:
* type: number
* description: Gross sum across quote positions
* totalQuantity:
* type: number
* description: Total quantity across quote positions
* customerName:
* type: string
* nullable: true
* Quote:
* allOf:
* - $ref: '#/components/schemas/QuoteSummary'

View File

@@ -43,6 +43,32 @@ export function register(app, basePath = '') {
* for the authenticated user's selected company.
* security:
* - cookieAuth: []
* parameters:
* - in: query
* name: offset
* schema:
* type: integer
* default: 0
* minimum: 0
* description: Number of quotes to skip
* - in: query
* name: limit
* schema:
* type: integer
* default: 50
* minimum: 1
* maximum: 100
* description: Number of quotes to return
* - in: query
* name: search
* schema:
* type: string
* description: Free-text search matching quote number, external number, or customer name
* - in: query
* name: seekMonths
* schema:
* type: integer
* description: Negative integer for cutoff months ago (e.g. -1 for quotes older than 1 month)
* x-markdown: quote/list.md
* responses:
* 200:
@@ -51,13 +77,26 @@ export function register(app, basePath = '') {
* application/json:
* schema:
* type: object
* required: [quotes, total, unfilteredTotal, offset, limit]
* properties:
* quotes:
* type: array
* items:
* $ref: '#/components/schemas/QuoteSummary'
* $ref: '#/components/schemas/Quote'
* total:
* type: integer
* description: Total number of filtered quotes
* unfilteredTotal:
* type: integer
* description: Total number of quotes without any filters applied
* offset:
* type: integer
* description: Number of quotes skipped
* limit:
* type: integer
* description: Number of quotes returned
* 400:
* description: No company selected
* description: Invalid query parameters, invalid offset, invalid limit, or no company selected
* content:
* application/json:
* schema:
@@ -167,9 +206,47 @@ 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 = 50;
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' });
}
}
const search = typeof req.query.search === 'string' && req.query.search.trim() !== ''
? req.query.search.trim()
: undefined;
let seekMonths = undefined;
if (req.query.seekMonths !== undefined && req.query.seekMonths !== '') {
const parsedSeek = parseInt(req.query.seekMonths, 10);
if (!Number.isInteger(parsedSeek)) {
return res.status(400).json({ error: 'seekMonths must be an integer' });
}
seekMonths = parsedSeek;
}
try {
const quotes = await db.list(req.user.id);
res.status(200).json({ quotes });
const result = await db.list(req.user.id, {
offset,
limit,
search,
seekMonths,
});
res.status(200).json(result);
} catch (error) {
const status = quoteErrorStatus(error);
if (status === 500) console.error('List quotes failed:', error);