Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

productRequest.ts 624B

123456789101112131415161718192021222324252627
  1. import apiEndpoints from '../apiEndpoints';
  2. interface ProductsResponse {
  3. message: string;
  4. product: object;
  5. productCount: number;
  6. next: string;
  7. previous: string;
  8. }
  9. export const getAllProducts = async (
  10. pageIndex: number,
  11. category = 'All',
  12. filter = 'asc'
  13. ): Promise<ProductsResponse> => {
  14. const response = await fetch(
  15. `http://localhost:3000${apiEndpoints.products}?pageIndex=${pageIndex}&category=${category}&filterType=${filter}`
  16. );
  17. const data: ProductsResponse = await response.json();
  18. if (!response.ok) {
  19. throw new Error(data.message || 'Something went wrong!');
  20. }
  21. return data;
  22. };