| 123456789101112131415161718192021222324252627 |
- import apiEndpoints from '../apiEndpoints';
-
- interface ProductsResponse {
- message: string;
- product: object;
- productCount: number;
- next: string;
- previous: string;
- }
-
- export const getAllProducts = async (
- pageIndex: number,
- category = 'All',
- filter = 'asc'
- ): Promise<ProductsResponse> => {
- const response = await fetch(
- `http://localhost:3000${apiEndpoints.products}?pageIndex=${pageIndex}&category=${category}&filterType=${filter}`
- );
-
- const data: ProductsResponse = await response.json();
-
- if (!response.ok) {
- throw new Error(data.message || 'Something went wrong!');
- }
-
- return data;
- };
|