admin big changes

This commit is contained in:
2026-06-13 17:38:35 +03:30
parent 213ef1a1b7
commit 0c404ee3e1
14 changed files with 188 additions and 276 deletions
+32
View File
@@ -0,0 +1,32 @@
import { getCategories, syncCategoriesFromProducts } from '@/api/category'
import type { Category } from '@/model/category'
import { PRODUCT_CATEGORY_ABSHODE } from '@/utils/productCategories'
export type CategorySelectItem = { key: string; value: string }
export function mapCategoriesToSelectItems(
rows: Category[],
metalHint = 'طلا، نقره، مس'
): CategorySelectItem[] {
return rows.map((category) => ({
key: category.name,
value:
category.name === PRODUCT_CATEGORY_ABSHODE
? `${category.name} (${metalHint})`
: category.name
}))
}
/** همان منبع جدول دسته‌بندی‌ها — قبل از خواندن، همگام‌سازی می‌کند */
export async function syncAndLoadCategories(options?: {
selectOnly?: boolean
metalHint?: string
}): Promise<CategorySelectItem[]> {
await syncCategoriesFromProducts()
const rows = await getCategories(
options?.selectOnly ? { select_only: true } : undefined
)
return mapCategoriesToSelectItems(rows, options?.metalHint)
}