26 lines
942 B
TypeScript
26 lines
942 B
TypeScript
import useAxios from '@core/utils/useAxios'
|
|
import type { Category, CategoryInput } from '@/model/category'
|
|
|
|
export type CategoryListParams = {
|
|
active?: number
|
|
select_only?: boolean
|
|
search?: string
|
|
}
|
|
|
|
export const getCategories = async (params?: CategoryListParams) =>
|
|
await useAxios.get<Category[]>('/admin/categories', { params })
|
|
|
|
export const createCategory = async (payload: CategoryInput) =>
|
|
await useAxios.post<Category>('/admin/categories', payload)
|
|
|
|
export const updateCategory = async (id: number, payload: Partial<CategoryInput>) =>
|
|
await useAxios.put<Category>(`/admin/categories/${id}`, payload)
|
|
|
|
export const syncCategoriesFromProducts = async () =>
|
|
await useAxios.post<{ message: string; created: number; items: Category[] }>(
|
|
'/admin/categories/sync-from-products'
|
|
)
|
|
|
|
export const changeCategoryActive = async (id: number, active: 0 | 1) =>
|
|
await useAxios.get(`/admin/categories/${id}/active/${active}`)
|