You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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. };