您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

productRequest.ts 569B

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