u
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,26 +1,85 @@
|
||||
import { getStore } from './store.js';
|
||||
|
||||
export async function list(googleAuthId) {
|
||||
function round2(num) {
|
||||
return Math.round((Number(num) || 0) * 100) / 100;
|
||||
}
|
||||
|
||||
function calculateQuoteGrossTotal(lines = []) {
|
||||
let total = 0;
|
||||
for (const line of lines) {
|
||||
const amount = Number(line.amount || 0);
|
||||
const net = Number(line.net || 0);
|
||||
const rebate = Number(line.rebate || 0);
|
||||
const taxrate = Number(line.taxrate || 0);
|
||||
const netAfterRebate = net * (1 - rebate / 100);
|
||||
const gross = netAfterRebate * (1 + taxrate / 100);
|
||||
total += amount * gross;
|
||||
}
|
||||
return round2(total);
|
||||
}
|
||||
|
||||
function calculateTotalQuantity(lines = []) {
|
||||
let qty = 0;
|
||||
for (const line of lines) {
|
||||
qty += Number(line.amount || 0);
|
||||
}
|
||||
return Math.round(qty * 1000) / 1000;
|
||||
}
|
||||
|
||||
function enrichQuote(quote) {
|
||||
if (!quote) return quote;
|
||||
const lines = Array.isArray(quote.lines) ? quote.lines : [];
|
||||
const positions = quote.positions !== undefined ? quote.positions : lines.length;
|
||||
const grossTotal = quote.grossTotal !== undefined ? quote.grossTotal : calculateQuoteGrossTotal(lines);
|
||||
const totalQuantity = quote.totalQuantity !== undefined ? quote.totalQuantity : calculateTotalQuantity(lines);
|
||||
|
||||
return {
|
||||
...quote,
|
||||
positions,
|
||||
grossTotal,
|
||||
totalQuantity,
|
||||
};
|
||||
}
|
||||
|
||||
export async function list(googleAuthId, opts) {
|
||||
const store = await getStore();
|
||||
return store.quote.list(googleAuthId);
|
||||
const result = await store.quote.list(googleAuthId, opts);
|
||||
if (Array.isArray(result)) {
|
||||
return result.map(enrichQuote);
|
||||
}
|
||||
if (result && Array.isArray(result.quotes)) {
|
||||
return {
|
||||
...result,
|
||||
quotes: result.quotes.map(enrichQuote),
|
||||
};
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function getById(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.quote.getById(googleAuthId, id);
|
||||
const quote = await store.quote.getById(googleAuthId, id);
|
||||
return enrichQuote(quote);
|
||||
}
|
||||
|
||||
export async function create(googleAuthId, data) {
|
||||
const store = await getStore();
|
||||
return store.quote.create(googleAuthId, data);
|
||||
const quote = await store.quote.create(googleAuthId, data);
|
||||
return enrichQuote(quote);
|
||||
}
|
||||
|
||||
export async function update(googleAuthId, id, data) {
|
||||
const store = await getStore();
|
||||
return store.quote.update(googleAuthId, id, data);
|
||||
const quote = await store.quote.update(googleAuthId, id, data);
|
||||
return enrichQuote(quote);
|
||||
}
|
||||
|
||||
export async function remove(googleAuthId, id) {
|
||||
const store = await getStore();
|
||||
return store.quote.delete(googleAuthId, id);
|
||||
}
|
||||
|
||||
export async function rebuildSummaries(googleAuthId) {
|
||||
const store = await getStore();
|
||||
return store.quote.rebuildSummaries(googleAuthId);
|
||||
}
|
||||
|
||||
@@ -261,7 +261,6 @@ export const TOOL_PARAMETER_DESCRIPTIONS = {
|
||||
};
|
||||
|
||||
export const PATCH_PARAMETER_DESCRIPTIONS = TOOL_PARAMETER_DESCRIPTIONS.patch;
|
||||
export const PATCH_PARAM_DESCRIPTIONS = TOOL_PARAMETER_DESCRIPTIONS.patch;
|
||||
export const ANALYZE_IMAGE_VISION_COMPARE_PROMPT =
|
||||
'Compare these images, evaluate visual quality, flag watermarks/overlays/defects, and state the best candidate with rationale.';
|
||||
export const ANALYZE_IMAGE_VISION_DESCRIBE_PROMPT =
|
||||
@@ -335,28 +334,23 @@ export async function buildSystemPrompt(vfsRoot, googleAuthId) {
|
||||
}
|
||||
|
||||
const today = new Date().toISOString().split('T')[0];
|
||||
|
||||
// 1. STATIC CORE FIRST (100% cacheable across all users, days, and VFS changes)
|
||||
const staticCore = [
|
||||
const basePrompt = [
|
||||
'QuixPOS Article Management System API Assistant',
|
||||
'[TESTSYSTEM: destructive commands allowed; primary goal is finding bugs]',
|
||||
'',
|
||||
SYSTEM_PROMPT_RULES,
|
||||
'',
|
||||
SYSTEM_PROMPT_ROUTE_MATRIX,
|
||||
].join('\n');
|
||||
|
||||
// 2. DYNAMIC / PER-TENANT STATE LAST (ordered from least-volatile to most-volatile)
|
||||
const dynamicContext = [
|
||||
'',
|
||||
`Date: ${today}`,
|
||||
'',
|
||||
buildSkillIndex(vfsRoot),
|
||||
].join('\n');
|
||||
|
||||
const sections = [staticCore, dynamicContext];
|
||||
const sections = [];
|
||||
if (prefix) sections.push(prefix);
|
||||
sections.push(basePrompt);
|
||||
if (suffix) sections.push(suffix);
|
||||
|
||||
return sections.join('\n\n');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user