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';
|
2025-06-03 17:13:44 +03:30
|
|
|
import api from '@/lib/axios';
|
2025-06-08 15:52:05 +03:30
|
|
|
import { IResponse } from '@/models/response';
|
|
|
|
|
import { cookies } from 'next/headers';
|
2025-06-03 17:13:44 +03:30
|
|
|
|
2025-06-08 15:52:05 +03:30
|
|
|
export async function getProductCategories() {
|
|
|
|
|
const cookiesStore = await cookies();
|
2025-06-03 17:13:44 +03:30
|
|
|
return api
|
2025-06-08 15:52:05 +03:30
|
|
|
.get('/product_categories', {
|
|
|
|
|
headers: {
|
|
|
|
|
Cookie: cookiesStore.toString(),
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-06-03 17:13:44 +03:30
|
|
|
.then(({ data }) => {
|
|
|
|
|
return Promise.resolve(data.data);
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => Promise.reject(error));
|
|
|
|
|
}
|
|
|
|
|
|
2025-06-08 15:52:05 +03:30
|
|
|
export async function getProductCategoryById(
|
2025-06-05 16:03:59 +03:30
|
|
|
categoryId: string,
|
|
|
|
|
): Promise<IProductCategoryCardProps> {
|
2025-06-08 15:52:05 +03:30
|
|
|
const cookiesStore = await cookies();
|
2025-06-03 17:13:44 +03:30
|
|
|
return api
|
2025-06-08 15:52:05 +03:30
|
|
|
.get(`/product_categories/${categoryId}`, {
|
|
|
|
|
headers: {
|
|
|
|
|
Cookie: cookiesStore.toString(),
|
|
|
|
|
},
|
|
|
|
|
})
|
2025-06-03 17:13:44 +03:30
|
|
|
.then(({ data }) => {
|
|
|
|
|
return Promise.resolve(data.data);
|
|
|
|
|
})
|
|
|
|
|
.catch((error) => Promise.reject(error));
|
|
|
|
|
}
|
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[]>> {
|
|
|
|
|
const cookiesStore = await cookies();
|
2025-06-19 15:48:47 +03:30
|
|
|
console.log('request');
|
|
|
|
|
console.log(page);
|
|
|
|
|
|
2025-06-05 16:03:59 +03:30
|
|
|
return api
|
2025-06-08 15:52:05 +03:30
|
|
|
.get(`/product_categories/${categoryId}/products`, {
|
|
|
|
|
headers: {
|
|
|
|
|
Cookie: cookiesStore.toString(),
|
|
|
|
|
},
|
|
|
|
|
params: { page },
|
|
|
|
|
})
|
2025-06-05 16:03:59 +03:30
|
|
|
.then(({ data }) => {
|
2025-06-08 15:52:05 +03:30
|
|
|
return Promise.resolve(data);
|
2025-06-05 16:03:59 +03:30
|
|
|
})
|
|
|
|
|
.catch((error) => Promise.reject(error));
|
|
|
|
|
}
|