Normalize category and product IDs to strings for int-ID API.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
d8ecd57641
commit
2af7bfde77
+3
-3
@@ -24,7 +24,7 @@ export type TechnicalField = {
|
|||||||
export type TechnicalData = Record<string, string>;
|
export type TechnicalData = Record<string, string>;
|
||||||
|
|
||||||
export type CategoryNode = {
|
export type CategoryNode = {
|
||||||
id: number | string;
|
id: string;
|
||||||
nameFa: string;
|
nameFa: string;
|
||||||
nameEn: string;
|
nameEn: string;
|
||||||
children?: CategoryNode[];
|
children?: CategoryNode[];
|
||||||
@@ -43,12 +43,12 @@ export type ProductVariantPrice = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export type Product = {
|
export type Product = {
|
||||||
id: number | string;
|
id: string;
|
||||||
nameFa: string;
|
nameFa: string;
|
||||||
nameEn: string;
|
nameEn: string;
|
||||||
summary?: string;
|
summary?: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
categoryId: number | string;
|
categoryId: string;
|
||||||
brandId: string;
|
brandId: string;
|
||||||
price: number;
|
price: number;
|
||||||
discountPrice?: number;
|
discountPrice?: number;
|
||||||
|
|||||||
@@ -71,12 +71,12 @@ export function mapVariant(v: ApiProductVariant): ProductVariantPrice {
|
|||||||
|
|
||||||
export function mapProduct(p: ApiProduct): Product {
|
export function mapProduct(p: ApiProduct): Product {
|
||||||
return {
|
return {
|
||||||
id: p.id,
|
id: String(p.id),
|
||||||
nameFa: p.nameFa,
|
nameFa: p.nameFa,
|
||||||
nameEn: p.nameEn ?? "",
|
nameEn: p.nameEn ?? "",
|
||||||
summary: p.summary ?? "",
|
summary: p.summary ?? "",
|
||||||
description: p.description ?? "",
|
description: p.description ?? "",
|
||||||
categoryId: p.categoryId ?? "",
|
categoryId: p.categoryId != null ? String(p.categoryId) : "",
|
||||||
brandId: p.brandId ?? "",
|
brandId: p.brandId ?? "",
|
||||||
price: p.price,
|
price: p.price,
|
||||||
discountPrice: p.discountPrice ?? undefined,
|
discountPrice: p.discountPrice ?? undefined,
|
||||||
@@ -264,7 +264,7 @@ function nestCategories(flat: ApiCategory[]): CategoryNode[] {
|
|||||||
(a, b) => a.sortOrder - b.sortOrder,
|
(a, b) => a.sortOrder - b.sortOrder,
|
||||||
);
|
);
|
||||||
return nodes.map((node) => ({
|
return nodes.map((node) => ({
|
||||||
id: node.id,
|
id: String(node.id),
|
||||||
nameFa: node.nameFa,
|
nameFa: node.nameFa,
|
||||||
nameEn: node.nameEn,
|
nameEn: node.nameEn,
|
||||||
variants: {
|
variants: {
|
||||||
@@ -284,7 +284,7 @@ export async function fetchCategoriesTree(): Promise<CategoryNode[]> {
|
|||||||
const rows = await api<ApiCategory[]>("/categories");
|
const rows = await api<ApiCategory[]>("/categories");
|
||||||
if (rows.some((r) => r.children && r.children.length)) {
|
if (rows.some((r) => r.children && r.children.length)) {
|
||||||
const mapNode = (node: ApiCategory): CategoryNode => ({
|
const mapNode = (node: ApiCategory): CategoryNode => ({
|
||||||
id: node.id,
|
id: String(node.id),
|
||||||
nameFa: node.nameFa,
|
nameFa: node.nameFa,
|
||||||
nameEn: node.nameEn,
|
nameEn: node.nameEn,
|
||||||
variants: {
|
variants: {
|
||||||
|
|||||||
Reference in New Issue
Block a user