Home Reference Source

src/cleanup_location.js

export default class CleanupLocation {
  constructor(cleanupLocation) {
    var requiredParams = ['id', 'latitude', 'longitude'];

    if (!cleanupLocation) {
      throw new Error('Requires cleanup location');
    } else if (requiredParams.map(param => param in cleanupLocation).some(param => param === false)) {
      throw new Error('Requires id, latitude', 'longitude');
    } else {
      this._locationInformation = {
        id: cleanupLocation.id,
        title: cleanupLocation.title.rendered,
        date: cleanupLocation.date ? cleanupLocation.date : 'TBD',
        content: cleanupLocation.content.rendered,
        latitude: cleanupLocation.latitude,
        longitude: cleanupLocation.longitude,
        image: cleanupLocation.map_image,
        address: cleanupLocation.address,
        city: cleanupLocation.city,
        state: cleanupLocation.state,
        country: cleanupLocation.country,
        startTime: cleanupLocation.start_time,
        endTime: cleanupLocation.end_time,
        cleanupType: cleanupLocation.cleanup_type,
        partnerOrg: cleanupLocation.partner_org,
        partnerName: cleanupLocation.partner_name,
        partnerLink: cleanupLocation.partner_link,
        partnerPhone: cleanupLocation.partner_phone,
        partnerEmail: cleanupLocation.partner_email,
        eventLink: cleanupLocation.event_link
      };
    }
  }

  /**
   * Returns the id from a location
   * @public
   *
   * @returns {integer} Image Url
   * @memberof CleanupLocation
   */
  id() {
    return this._locationInformation.id;
  }

  /**
   * Returns the image url from a location
   * @public
   *
   * @returns {string} Image Url
   * @memberof CleanupLocation
   */
  image() {
    return this._locationInformation.image;
  }

  /**
   * Returns the city string of a location
   * @public
   *
   * @returns {string} City
   * @memberof CleanupLocation
   */
  city() {
    return this._locationInformation.city;
  }

  /**
   * Returns the state string of a location
   * @public
   *
   * @returns {string} State
   * @memberof CleanupLocation
   */
  state() {
    return this._locationInformation.state;
  }

  /**
   * Returns the country of a given location
   * @public
   *
   * @returns {string} Country
   * @memberof CleanupLocation
   */
  country() {
    return this._locationInformation.country;
  }

  /**
   * Returns the start time of a given location
   * @public
   *
   * @returns {string>}
   * @memberof CleanupLocation
   */
  startTime() {
    return this._locationInformation.startTime;
  }

  /**
   * Returns the end time of a given location
   * @public
   *
   * @returns {string}
   * @memberof CleanupLocation
   */
  endTime() {
    return this._locationInformation.endTime;
  }

  /**
   * Returns the latitude of a given location
   * @public
   *
   * @returns {string} Latitude
   * @memberof CleanupLocation
   */
  latitude() {
    return this._locationInformation.latitude;
  }

  /**
   * Returns the longitude of a given location
   * @public
   *
   * @returns {string} Longitude
   * @memberof CleanupLocation
   */
  longitude() {
    return this._locationInformation.longitude;
  }

  /**
   * Returns the title of a given location
   * @public
   *
   * @returns {string} Title
   * @memberof CleanupLocation
   */
  title() {
    return this._locationInformation.title;
  }

  /**
   * Returns the partner organization of a given location
   * @public
   *
   * @returns {string} Title
   * @memberof CleanupLocation
   */
  partnerOrg() {
    return this._locationInformation.partnerOrg;
  }
};