methods/fetch-order.js

  1. import { store } from '@ecomplus/client'
  2. /**
  3. * @method
  4. * @name EcomPassport#fetchOrder
  5. * @description Fetch order by ID from Passport API (if authorized) or Store API (public).
  6. *
  7. * @param {string} orderId - Object ID (`_id`) of the order to be fetched
  8. *
  9. * @returns {Promise<data|error>}
  10. *
  11. * @example
  12. ecomPassport.fetchOrder(orderId).then(order => {
  13. console.log(order._id)
  14. })
  15. */
  16. export default ({ storeId, checkAuthorization, requestApi }, emitter, [orderId]) => {
  17. const url = `/api/orders/${orderId}.json`
  18. let req
  19. if (checkAuthorization()) {
  20. req = requestApi(url)
  21. } else {
  22. req = store({ url, storeId })
  23. }
  24. return req.then(({ data }) => data)
  25. }