feat: catalog read cache (api + user apps) and clearer Zarrin accounting errors

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
s.esmaeili
2026-10-11 14:31:32 +03:30
co-authored by Cursor
parent 561addc676
commit 574fa1b4aa
53 changed files with 1241 additions and 401 deletions
@@ -1,39 +1,16 @@
// The real GET /customers/:id/orders endpoint returns OrderItem rows with
// only `productVariantId` (no nested product/variant title) — this joins
// against the already-existing GET /catalog/products list client-side rather
// against the shared catalogue (stores/catalogStore.ts) client-side rather
// than touching apps/api to add an include.
import { ref } from 'vue'
import { api } from '../api/client'
import { useCatalogStore, type VariantLookup } from '../stores/catalogStore'
export interface VariantLookup {
productTitle: string
variantTitle: string
imageUrl?: string
}
const cache = ref<Map<string, VariantLookup> | null>(null)
async function ensureLoaded() {
if (cache.value) return cache.value
const products = await api.listProducts()
const map = new Map<string, VariantLookup>()
for (const product of products) {
for (const variant of product.variants) {
map.set(variant.id, {
productTitle: product.title,
variantTitle: variant.title,
imageUrl: product.images[0]?.url,
})
}
}
cache.value = map
return map
}
export type { VariantLookup }
export function useOrderItemProduct() {
const catalog = useCatalogStore()
const lookup = async (productVariantId: string): Promise<VariantLookup | undefined> => {
const map = await ensureLoaded()
return map.get(productVariantId)
if (!catalog.loaded) await catalog.load()
return catalog.variantLookup.get(productVariantId)
}
return { lookup }
}