Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -10,9 +10,9 @@ function toNumber (value) {
|
||||
return Number.isFinite(n) ? Number(n.toFixed(2)) : 0
|
||||
}
|
||||
|
||||
function mapRow (raw, index, offset = 0) {
|
||||
function mapRow (raw, index, baseIndex = 0) {
|
||||
return {
|
||||
id: offset + index + 1,
|
||||
id: baseIndex + index + 1,
|
||||
productCode: toText(raw?.ProductCode),
|
||||
stockQty: toNumber(raw?.StockQty),
|
||||
stockEntryDate: toText(raw?.StockEntryDate),
|
||||
@@ -64,27 +64,31 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
|
||||
this.loading = true
|
||||
this.error = ''
|
||||
const limit = Number(options?.limit) > 0 ? Number(options.limit) : 500
|
||||
const offset = Number(options?.offset) >= 0 ? Number(options.offset) : 0
|
||||
const afterProductCode = toText(options?.afterProductCode)
|
||||
const append = Boolean(options?.append)
|
||||
const baseIndex = append ? this.rows.length : 0
|
||||
const startedAt = Date.now()
|
||||
console.info('[product-pricing][frontend] request:start', {
|
||||
at: new Date(startedAt).toISOString(),
|
||||
timeout_ms: 180000,
|
||||
limit,
|
||||
offset,
|
||||
after_product_code: afterProductCode || null,
|
||||
append
|
||||
})
|
||||
try {
|
||||
const params = { limit }
|
||||
if (afterProductCode) params.after_product_code = afterProductCode
|
||||
const res = await api.request({
|
||||
method: 'GET',
|
||||
url: '/pricing/products',
|
||||
params: { limit, offset },
|
||||
params,
|
||||
timeout: 180000
|
||||
})
|
||||
const traceId = res?.headers?.['x-trace-id'] || null
|
||||
const hasMoreHeader = String(res?.headers?.['x-has-more'] || '').toLowerCase()
|
||||
const nextCursorHeader = toText(res?.headers?.['x-next-cursor'])
|
||||
const data = Array.isArray(res?.data) ? res.data : []
|
||||
const mapped = data.map((x, i) => mapRow(x, i, offset))
|
||||
const mapped = data.map((x, i) => mapRow(x, i, baseIndex))
|
||||
if (append) {
|
||||
const merged = [...this.rows]
|
||||
const seen = new Set(this.rows.map((x) => x?.productCode))
|
||||
@@ -104,12 +108,14 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
|
||||
duration_ms: Date.now() - startedAt,
|
||||
row_count: this.rows.length,
|
||||
fetched_count: mapped.length,
|
||||
has_more: this.hasMore
|
||||
has_more: this.hasMore,
|
||||
next_cursor: nextCursorHeader || null
|
||||
})
|
||||
return {
|
||||
traceId,
|
||||
fetched: mapped.length,
|
||||
hasMore: this.hasMore
|
||||
hasMore: this.hasMore,
|
||||
nextCursor: nextCursorHeader
|
||||
}
|
||||
} catch (err) {
|
||||
if (!append) this.rows = []
|
||||
|
||||
Reference in New Issue
Block a user