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