From 2af7bfde77e180cdcfe987f4a6165e444f7e648e Mon Sep 17 00:00:00 2001 From: Alireza Hassani Date: Sun, 27 Sep 2026 18:49:54 +0330 Subject: [PATCH] Normalize category and product IDs to strings for int-ID API. Co-authored-by: Cursor --- src/data/clothes.ts | 6 +++--- src/lib/clothes-api.ts | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/data/clothes.ts b/src/data/clothes.ts index 1540e76..155352d 100644 --- a/src/data/clothes.ts +++ b/src/data/clothes.ts @@ -24,7 +24,7 @@ export type TechnicalField = { export type TechnicalData = Record; export type CategoryNode = { - id: number | string; + id: string; nameFa: string; nameEn: string; children?: CategoryNode[]; @@ -43,12 +43,12 @@ export type ProductVariantPrice = { }; export type Product = { - id: number | string; + id: string; nameFa: string; nameEn: string; summary?: string; description?: string; - categoryId: number | string; + categoryId: string; brandId: string; price: number; discountPrice?: number; diff --git a/src/lib/clothes-api.ts b/src/lib/clothes-api.ts index a7e4ba6..5c96c12 100644 --- a/src/lib/clothes-api.ts +++ b/src/lib/clothes-api.ts @@ -71,12 +71,12 @@ export function mapVariant(v: ApiProductVariant): ProductVariantPrice { export function mapProduct(p: ApiProduct): Product { return { - id: p.id, + id: String(p.id), nameFa: p.nameFa, nameEn: p.nameEn ?? "", summary: p.summary ?? "", description: p.description ?? "", - categoryId: p.categoryId ?? "", + categoryId: p.categoryId != null ? String(p.categoryId) : "", brandId: p.brandId ?? "", price: p.price, discountPrice: p.discountPrice ?? undefined, @@ -264,7 +264,7 @@ function nestCategories(flat: ApiCategory[]): CategoryNode[] { (a, b) => a.sortOrder - b.sortOrder, ); return nodes.map((node) => ({ - id: node.id, + id: String(node.id), nameFa: node.nameFa, nameEn: node.nameEn, variants: { @@ -284,7 +284,7 @@ export async function fetchCategoriesTree(): Promise { const rows = await api("/categories"); if (rows.some((r) => r.children && r.children.length)) { const mapNode = (node: ApiCategory): CategoryNode => ({ - id: node.id, + id: String(node.id), nameFa: node.nameFa, nameEn: node.nameEn, variants: {