2025-06-08 15:52:05 +03:30
|
|
|
'use server';
|
|
|
|
|
|
2025-06-05 16:03:59 +03:30
|
|
|
import type { IProductCategoryCardProps } from '@/components/pages/productCategories/productCategoryCard.d';
|
2025-06-09 11:29:54 +03:30
|
|
|
import type { IProductCardProps } from '@/components/pages/products/productCard/productCard.d';
|
2026-07-19 07:59:16 +03:30
|
|
|
import { serverGet } from '@/lib/server-api';
|
2025-06-08 15:52:05 +03:30
|
|
|
import { IResponse } from '@/models/response';
|
2025-06-03 17:13:44 +03:30
|
|
|
|
2025-06-08 15:52:05 +03:30
|
|
|
export async function getProductCategories() {
|
2026-07-19 07:59:16 +03:30
|
|
|
const data = await serverGet<{ data: IProductCategoryCardProps[] }>(
|
|
|
|
|
'/product_categories',
|
|
|
|
|
);
|
|
|
|
|
return data.data;
|
2025-06-03 17:13:44 +03:30
|
|
|
}
|
|
|
|
|
|
2025-06-08 15:52:05 +03:30
|
|
|
export async function getProductCategoryById(
|
2025-06-05 16:03:59 +03:30
|
|
|
categoryId: string,
|
|
|
|
|
): Promise<IProductCategoryCardProps> {
|
2026-07-19 07:59:16 +03:30
|
|
|
const data = await serverGet<{ data: IProductCategoryCardProps }>(
|
|
|
|
|
`/product_categories/${categoryId}`,
|
|
|
|
|
);
|
|
|
|
|
return data.data;
|
2025-06-03 17:13:44 +03:30
|
|
|
}
|
2025-06-05 16:03:59 +03:30
|
|
|
|
2025-06-08 15:52:05 +03:30
|
|
|
export async function getProducts(
|
|
|
|
|
categoryId: string,
|
|
|
|
|
page = 1,
|
|
|
|
|
): Promise<IResponse<IProductCardProps[]>> {
|
2026-07-19 07:59:16 +03:30
|
|
|
return serverGet<IResponse<IProductCardProps[]>>(
|
|
|
|
|
`/product_categories/${categoryId}/products`,
|
|
|
|
|
{
|
2025-06-08 15:52:05 +03:30
|
|
|
params: { page },
|
2026-07-19 07:59:16 +03:30
|
|
|
},
|
|
|
|
|
);
|
2025-06-05 16:03:59 +03:30
|
|
|
}
|