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.

featuredProductsRequest.ts 683B

12345678910111213141516171819202122232425262728
  1. import { ProductData } from '../../utils/interface/productInterface';
  2. import apiEndpoints from '../apiEndpoints';
  3. interface ProductDataDB extends ProductData {
  4. id: string;
  5. _id: string;
  6. __v: number;
  7. }
  8. interface FeaturedProductsResponse {
  9. message: string;
  10. featuredProducts: Array<ProductDataDB>;
  11. }
  12. export const getFeaturedProducts =
  13. async (): Promise<FeaturedProductsResponse> => {
  14. const response = await fetch(
  15. `http://localhost:3000${apiEndpoints.featuredProducts}`
  16. );
  17. const data: FeaturedProductsResponse = await response.json();
  18. if (!response.ok) {
  19. throw new Error(data.message || 'Something went wrong!');
  20. }
  21. return data;
  22. };