Untitled

 avatar
unknown
plain_text
2 months ago
1.8 kB
3
Indexable
const keys = [
        "beaconFull",
        "cateringFull",
        "fboFull",
        "hotelFull",
        "otherFull",
        "slotFull",
        "supplyFull",
        "taxiFull",
        "ticketFull",
      ];

const getOriginStretchs = async (bookingID) => {
  try {
    const response = await axios.get('/api/v1/bookings/' + bookingID);
    const booking = response.data.data.stretchsFull;
    const originStretchs = [];

    if (booking) {

      for (const stretch of Object.values(booking)) {
        if (stretch.originFull) {
          keys.forEach((key) => {
            if (
              stretch.originFull[key] &&
              Object.keys(stretch.originFull[key]).length !== 0
            ) {
              originStretchs.push(stretch.originFull[key]);
            }
          });
        }
      }
    }

    return originStretchs;
  } catch (error) {
    console.log('Error fetching origin stretchs:', error);
    return [];
  }
};



const getDestinyStretchs = async (bookingID) => {
  try {
    const response = await axios.get('/api/v1/bookings/' + bookingID);
    const booking = response.data.data.stretchsFull;
    const destinyStretchs = [];

    if (booking) {

      for (const stretch of Object.values(booking)) {
        if (stretch.destinyFull) {
          keys.forEach((key) => {
            if (
              stretch.destinyFull[key] &&
              Object.keys(stretch.destinyFull[key]).length !== 0
            ) {
              destinyStretchs.push(stretch.destinyFull[key]);
            }
          });
        }
      }
    }

    return destinyStretchs;
  } catch (error) {
    console.log('Error fetching destiny stretchs:', error);
    return [];
  }
};
Leave a Comment