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.

getOrdersForOwnerRequest.ts 621B

123456789101112131415161718192021222324252627
  1. import apiEndpoints from '../apiEndpoints';
  2. import { OrderData } from '../../utils/interface/orderInterface';
  3. interface OrderDataDB extends OrderData {
  4. id: string;
  5. _id: string;
  6. __v: number;
  7. }
  8. interface OrderResponse {
  9. message: string;
  10. orders: Array<OrderDataDB>;
  11. }
  12. export const getOrdersForOwner = async (id: string): Promise<OrderResponse> => {
  13. const response = await fetch(
  14. `http://localhost:3000${apiEndpoints.order}?ownerID=${id}`
  15. );
  16. const data: OrderResponse = await response.json();
  17. if (!response.ok) {
  18. throw new Error(data.message || 'Something went wrong!');
  19. }
  20. return data;
  21. };