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) {
|
||||
function mapRow (raw, index, offset = 0) {
|
||||
return {
|
||||
id: index + 1,
|
||||
id: offset + index + 1,
|
||||
productCode: toText(raw?.ProductCode),
|
||||
stockQty: toNumber(raw?.StockQty),
|
||||
stockEntryDate: toText(raw?.StockEntryDate),
|
||||
@@ -55,34 +55,65 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
|
||||
state: () => ({
|
||||
rows: [],
|
||||
loading: false,
|
||||
error: ''
|
||||
error: '',
|
||||
hasMore: true
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchRows () {
|
||||
async fetchRows (options = {}) {
|
||||
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 append = Boolean(options?.append)
|
||||
const startedAt = Date.now()
|
||||
console.info('[product-pricing][frontend] request:start', {
|
||||
at: new Date(startedAt).toISOString(),
|
||||
timeout_ms: 600000
|
||||
timeout_ms: 180000,
|
||||
limit,
|
||||
offset,
|
||||
append
|
||||
})
|
||||
try {
|
||||
const res = await api.request({
|
||||
method: 'GET',
|
||||
url: '/pricing/products',
|
||||
timeout: 600000
|
||||
params: { limit, offset },
|
||||
timeout: 180000
|
||||
})
|
||||
const traceId = res?.headers?.['x-trace-id'] || null
|
||||
const hasMoreHeader = String(res?.headers?.['x-has-more'] || '').toLowerCase()
|
||||
const data = Array.isArray(res?.data) ? res.data : []
|
||||
this.rows = data.map((x, i) => mapRow(x, i))
|
||||
const mapped = data.map((x, i) => mapRow(x, i, offset))
|
||||
if (append) {
|
||||
const merged = [...this.rows]
|
||||
const seen = new Set(this.rows.map((x) => x?.productCode))
|
||||
for (const row of mapped) {
|
||||
const key = row?.productCode
|
||||
if (key && seen.has(key)) continue
|
||||
merged.push(row)
|
||||
if (key) seen.add(key)
|
||||
}
|
||||
this.rows = merged
|
||||
} else {
|
||||
this.rows = mapped
|
||||
}
|
||||
this.hasMore = hasMoreHeader ? hasMoreHeader === 'true' : mapped.length === limit
|
||||
console.info('[product-pricing][frontend] request:success', {
|
||||
trace_id: traceId,
|
||||
duration_ms: Date.now() - startedAt,
|
||||
row_count: this.rows.length
|
||||
row_count: this.rows.length,
|
||||
fetched_count: mapped.length,
|
||||
has_more: this.hasMore
|
||||
})
|
||||
return {
|
||||
traceId,
|
||||
fetched: mapped.length,
|
||||
hasMore: this.hasMore
|
||||
}
|
||||
} catch (err) {
|
||||
this.rows = []
|
||||
if (!append) this.rows = []
|
||||
this.hasMore = false
|
||||
const msg = err?.response?.data || err?.message || 'Urun fiyatlandirma listesi alinamadi'
|
||||
this.error = toText(msg)
|
||||
console.error('[product-pricing][frontend] request:error', {
|
||||
@@ -92,6 +123,7 @@ export const useProductPricingStore = defineStore('product-pricing-store', {
|
||||
status: err?.response?.status || null,
|
||||
message: this.error
|
||||
})
|
||||
throw err
|
||||
} finally {
|
||||
this.loading = false
|
||||
}
|
||||
|
||||
@@ -10,12 +10,27 @@ export const useTranslationStore = defineStore('translation', {
|
||||
}),
|
||||
|
||||
actions: {
|
||||
async fetchRows (filters = {}) {
|
||||
async fetchRows (filters = {}, options = {}) {
|
||||
this.loading = true
|
||||
const append = Boolean(options?.append)
|
||||
try {
|
||||
const res = await api.get('/language/translations', { params: filters })
|
||||
const payload = res?.data || {}
|
||||
this.rows = Array.isArray(payload.rows) ? payload.rows : []
|
||||
const incoming = Array.isArray(payload.rows) ? payload.rows : []
|
||||
if (append) {
|
||||
const merged = [...this.rows]
|
||||
const seen = new Set(this.rows.map((x) => x?.id))
|
||||
for (const row of incoming) {
|
||||
const id = row?.id
|
||||
if (!seen.has(id)) {
|
||||
merged.push(row)
|
||||
seen.add(id)
|
||||
}
|
||||
}
|
||||
this.rows = merged
|
||||
} else {
|
||||
this.rows = incoming
|
||||
}
|
||||
this.count = Number(payload.count) || this.rows.length
|
||||
} finally {
|
||||
this.loading = false
|
||||
|
||||
Reference in New Issue
Block a user