UNPKG

@publidata/utils-data-manager

Version:

Collection of methods to extract data from publidata

368 lines (317 loc) 8.65 kB
const kebabCase = require("lodash/kebabCase"); const { getAddress, getStreet, getCity, getOpeningHours, getTypeIcon, getTypeColor, getInfoFromMeta, getObjectBlurb, getFacilityTypeIdTranslation, getAllTheFacilityTypeIdTranslation, getFacilityTypeIdPluralTranslation, getFacilityTypeIdTranslationShort } = require("@publidata/utils-mapper"); const defaultIcons = require("../../assets/default-icons.json"); const PublidataObject = require("../"); /** * Class representing a facility. * @extends PublidataObject */ class PublidataObjectFacility extends PublidataObject { /** * @return {String} */ get blurb() { const blurb = getObjectBlurb(this.object); return this.memoize("blurb", blurb); } /** * @return {String} */ get openingHours() { const openingHours = getOpeningHours(this.object); return this.memoize("openingHours", openingHours); } /** * @return {String} */ get openingHoursBlurb() { const openingHoursBlurb = this.object._source.opening_hours_blurb; return this.memoize("openingHoursBlurb", openingHoursBlurb); } /** * @return {Array} */ get schedules() { const { schedules } = this.object._source; return this.memoize("schedules", schedules); } /** * @return {String} - Facility address */ get address() { const address = getAddress(this.object); return this.memoize("address", address); } /** * @return {String} - Facility address */ get addressInformations() { const { address_informations } = this.object._source; return this.memoize("addressInformations", address_informations); } /** * @return {String} - Facility street */ get street() { if (this.address) { const street = getStreet(this.address); return this.memoize("street", street); } return this.memoize("street", ""); } /** * @return {String} - Facility city */ get city() { if (this.address) { const { city } = getCity(this.address); return this.memoize("city", city); } return this.memoize("city", ""); } get cover() { const { cover_picture } = this.object._source; if (cover_picture) return this.memoize("cover", cover_picture.url); return this.memoize("cover", ""); } get profilePicture() { const { profile_picture } = this.object._source; if (profile_picture) return this.memoize("profilePicture", profile_picture.url); return this.memoize("profilePicture", ""); } /** * @return {String} - String which display cityStreet */ get cityStreet() { const cityStreet = `${this.city} - ${this.street}`; return this.memoize("cityStreet", cityStreet); } /** * @return {Object} - location of the facility * @return {Number} - location.lon - Longitude * @return {Number} - location.lat - Latitude */ get location() { return this.memoize("location", this.data.location); } /** * @return {Object} - Facility type object * @return {Number} facilityType.id - Id of facilityType * @return {String} facilityType.name - Name of facilityType */ get facilityType() { return this.memoize("facilityType", this.data.facility_type); } /** * @return {Array} - Contacts of the facility */ get contacts() { return this.memoize("contacts", this.data.contacts, true); } /** * @return {Array} - Contacts of the facility */ get bookings() { return this.memoize("bookings", this.data.bookings); } /** * @return {Array} - Facility services */ get services() { const services = this.data.services || []; return this.memoize("services", services); } /** * @return {Array of object} - All related cameras */ get cameras() { const cameras = this.data.cameras || []; return this.memoize("cameras", cameras); } /** * @return {Object} - Main camera */ get camera() { return this.memoize("camera", this.cameras[0] || null); } /** * @return {Array} - Facility fees */ get fees() { const fees = this.data.fees || []; return this.memoize("fees", fees); } get color() { return this.memoize( "color", getTypeColor(this.facilityType, this.instance.custom_settings.colors) ); } get icon() { const icon = this.memoize( "icon", getTypeIcon(kebabCase(this.facilityType.name), this.instance.icons), true ); if (icon) return icon; return this.memoize( "icon", getTypeIcon(kebabCase(this.facilityType.name), defaultIcons), true ); } get images() { return this.memoize("images", this.data.images); } get allTheFacilityTypeIdTranslation() { if (this.instance.custom_settings) { return this.memoize( "allTheFacilityTypeIdTranslation", getAllTheFacilityTypeIdTranslation( this.facilityType.id, this.instance.custom_settings ) ); } return this.memoize( "allTheFacilityTypeIdTranslation", getAllTheFacilityTypeIdTranslation(this.facilityType.id, this.instance) ); } get facilityTypeIdPluralTranslation() { if (this.instance.custom_settings) { return this.memoize( "facilityTypeIdPluralTranslation", getFacilityTypeIdPluralTranslation( this.facilityType.id, this.instance.custom_settings ) ); } return this.memoize( "facilityTypeIdPluralTranslation", getFacilityTypeIdPluralTranslation(this.facilityType.id, this.instance) ); } get facilityTypeIdTranslation() { if (this.instance.custom_settings) { return this.memoize( "facilityTypeIdTranslation", getFacilityTypeIdTranslation( this.facilityType.id, this.instance.custom_settings ) ); } return this.memoize( "facilityTypeIdTranslation", getFacilityTypeIdTranslation(this.facilityType.id, this.instance) ); } get facilityTypeIdTranslationShort() { if (this.instance.custom_settings) { return this.memoize( "facilityTypeIdTranslationShort", getFacilityTypeIdTranslationShort( this.facilityType.id, this.instance.custom_settings ) ); } return this.memoize( "facilityTypeIdTranslationShort", getFacilityTypeIdTranslationShort(this.facilityType.id, this.instance) ); } /** * @return {Object} */ get clickAndCollect() { const clickAndCollect = this.object._source.pick_up; return this.memoize("clickAndCollect", clickAndCollect); } get clickAndCollectBlurb() { const { clickAndCollect } = this; return this.memoize( "clickAndCollectBlurb", clickAndCollect ? clickAndCollect.blurb : "" ); } get clickAndCollectOpeningHours() { const { clickAndCollect } = this; return this.memoize( "clickAndCollectOpeningHours", clickAndCollect ? clickAndCollect.opening_hours : "" ); } /** * @return {Object} */ get homeDelivery() { const homeDelivery = this.object._source.home_delivery; return this.memoize("homeDelivery", homeDelivery); } get homeDeliveryOpeningHours() { const { homeDelivery } = this; return this.memoize( "homeDeliveryOpeningHours", homeDelivery ? homeDelivery.opening_hours : "" ); } get homeDeliveryBookingOpeningHours() { const { homeDelivery } = this; return this.memoize( "homeDeliveryBookingOpeningHours", homeDelivery ? homeDelivery.booking : "" ); } get homeDeliveryBlurb() { const { homeDelivery } = this; return this.memoize( "homeDeliveryBlurb", homeDelivery ? homeDelivery.blurb : "" ); } get covidFaceMask() { const covidFaceMask = getInfoFromMeta(this.object, "covid_face_mask"); return this.memoize("covidFaceMask", covidFaceMask); } get alerts() { return this.memoize("alerts", this.object._source.alerts); } get accessibility() { const accessibility = this.object._source.accessibility; return this.memoize("accessibility", accessibility); } get accessType() { const accessType = getInfoFromMeta(this.object, "access_type"); return this.memoize("accessType", accessType); } get isCliiink() { const isCliiink = this.accessType === "Cliiink"; return this.memoize("isCliiink", isCliiink); } /* * @param {array} contacts * @return {PublidataFacility} Current Facility */ setContacts(contacts) { this.memoize("contacts", contacts, true); return this; } } module.exports = PublidataObjectFacility;