UNPKG

@stratusjs/idx

Version:

AngularJS idx/property Service and Components bundle to be used as an add on to StratusJS

909 lines (907 loc) 481 kB
System.register(['lodash', '@stratusjs/runtime/stratus', 'angular', '@stratusjs/angularjs/services/model', '@stratusjs/angularjs/services/collection', '@stratusjs/core/misc', '@stratusjs/core/environment', '@stratusjs/idx/listTrac', '@stratusjs/core/dom', 'moment', '@stratusjs/angularjs-extras/filters/numeral', '@stratusjs/angular', 'angular-material', 'angular-sanitize', '@stratusjs/angularjs-extras', '@stratusjs/swiper'], (function () { 'use strict'; var uniqueId, clone, isString, isPlainObject, isArray, isEmpty, isEqual, isNumber, isObject, get, extend, isDate, isUndefined, isNil, cloneDeep, forEach, trim, camelCase, compact, union, _, includes, intersection, map, throttle, Stratus, element, Model, Collection, getHashBangParam, setHashBangParam, isJSON, safeUniqueId, hydrate, cookie, DOMComplete, moment, numeralFormat; return { setters: [function (module) { uniqueId = module.uniqueId; clone = module.clone; isString = module.isString; isPlainObject = module.isPlainObject; isArray = module.isArray; isEmpty = module.isEmpty; isEqual = module.isEqual; isNumber = module.isNumber; isObject = module.isObject; get = module.get; extend = module.extend; isDate = module.isDate; isUndefined = module.isUndefined; isNil = module.isNil; cloneDeep = module.cloneDeep; forEach = module.forEach; trim = module.trim; camelCase = module.camelCase; compact = module.compact; union = module.union; _ = module.default; includes = module.includes; intersection = module.intersection; map = module.map; throttle = module.throttle; }, function (module) { Stratus = module.Stratus; }, function (module) { element = module.element; }, function (module) { Model = module.Model; }, function (module) { Collection = module.Collection; }, function (module) { getHashBangParam = module.getHashBangParam; setHashBangParam = module.setHashBangParam; isJSON = module.isJSON; safeUniqueId = module.safeUniqueId; hydrate = module.hydrate; }, function (module) { cookie = module.cookie; }, null, function (module) { DOMComplete = module.DOMComplete; }, function (module) { moment = module.default; }, function (module) { numeralFormat = module.numeralFormat; }, null, null, null, null, null], execute: (function () { var __awaiter$b = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; const apiVersion = '3.13.0'; const angularJsService = ($http, $mdToast, $q, $rootScope, $window, ListTrac, orderByFilter) => { const sharedValues = { contactUrl: null, contactCommentVariable: null, contact: null, integrations: { analytics: {}, maps: {} } }; const defaultWhereOptions = { City: [], eCity: [], UnparsedAddress: [], StreetAddress: [], eStreetAddress: [], Location: '', eLocation: '', Status: [], ListingId: [], ListingType: [], CountyOrParish: [], eCountyOrParish: [], MLSAreaMajor: [], eMLSAreaMajor: [], MLSAreaMinor: [], eMLSAreaMinor: [], SubdivisionName: [], eSubdivisionName: [], Neighborhood: [], eNeighborhood: [], PostalCode: [], CityRegion: [], eCityRegion: [], AgentLicense: [], OfficeNumber: [], OfficeName: [] }; let idxServicesEnabled = []; let tokenRefreshURL = '/ajax/request?class=property.token_auth&method=getToken'; let sessionInitialized = false; let refreshLoginTimer; let defaultPageTitle; const instance = { disclaimer: {}, map: {}, member: { details: {}, list: {}, search: {} }, office: { details: {}, list: {}, search: {} }, property: { details: {}, list: {}, search: {} } }; const instanceLink = { Disclaimer: {}, List: {}, Map: {}, Search: {} }; const instanceOnEmitters = {}; const session = { services: [], lastCreated: new Date(), lastTtl: 0, contacts: [] }; const urlOptions = { Listing: {}, Search: {} }; const lastQueries = { whereFilter: {}, pages: [], perPage: 0, time: null }; function emit(emitterName, $scope, var1, var2, var3) { emitManual(emitterName, $scope.elementId, $scope, var1, var2, var3); } function emitManual(emitterName, uid, $scope, var1, var2, var3) { var _a, _b; var _c; if (Object.prototype.hasOwnProperty.call(instanceOnEmitters, uid) && Object.prototype.hasOwnProperty.call(instanceOnEmitters[uid], emitterName)) { Object.values(instanceOnEmitters[uid][emitterName]).forEach((emitter) => { try { emitter($scope, var1, var2, var3); } catch (e) { console.error(e, 'issue sending back emitter on', uid, emitterName, emitter); } }); } if (emitterName === 'init') { (_a = instanceOnEmitters[uid]) !== null && _a !== void 0 ? _a : (instanceOnEmitters[uid] = {}); (_b = (_c = instanceOnEmitters[uid])[emitterName]) !== null && _b !== void 0 ? _b : (_c[emitterName] = {}); } } function removeOnManual(emitterName, emitterId, onId) { if (Object.prototype.hasOwnProperty.call(instanceOnEmitters, emitterId) && Object.prototype.hasOwnProperty.call(instanceOnEmitters[emitterId], emitterName) && Object.prototype.hasOwnProperty.call(instanceOnEmitters[emitterId][emitterName], onId)) { delete instanceOnEmitters[emitterId][emitterName][onId]; } } function on(uid, emitterName, callback) { if (emitterName === 'init' && Object.prototype.hasOwnProperty.call(instanceOnEmitters, uid) && Object.prototype.hasOwnProperty.call(instanceOnEmitters[uid], emitterName) && Object.prototype.hasOwnProperty.call(Stratus.Instances, uid)) { callback(Stratus.Instances[uid]); return; } if (uid === 'Idx' && emitterName === 'sessionInit' && sessionInitialized) { callback(null); return; } if (!Object.prototype.hasOwnProperty.call(instanceOnEmitters, uid)) { instanceOnEmitters[uid] = {}; } if (!Object.prototype.hasOwnProperty.call(instanceOnEmitters[uid], emitterName)) { instanceOnEmitters[uid][emitterName] = {}; } const onId = uniqueId(); instanceOnEmitters[uid][emitterName][onId] = callback; return () => { removeOnManual(uid, emitterName, onId); }; } function registerDetailsInstance(uid, moduleName, $scope) { instance[moduleName].details[uid] = $scope; } function registerListInstance(uid, moduleName, $scope) { if (!Object.prototype.hasOwnProperty.call(instance, moduleName)) { instance[moduleName].list = {}; } instance[moduleName].list[uid] = $scope; if (!Object.prototype.hasOwnProperty.call(instanceLink.List, uid)) { instanceLink.List[uid] = []; } } function registerSearchInstance(uid, moduleName, $scope, listUid) { instance[moduleName].search[uid] = $scope; if (!Object.prototype.hasOwnProperty.call(instanceLink.Search, uid)) { instanceLink.Search[uid] = []; } if (listUid) { instanceLink.Search[uid].push(listUid); if (!Object.prototype.hasOwnProperty.call(instanceLink.List, listUid)) { instanceLink.List[listUid] = []; } instanceLink.List[listUid].push(uid); } } function unregisterDetailsInstance(uid, moduleName) { if (Object.prototype.hasOwnProperty.call(instance[moduleName].details, uid)) { const detailUid = instance[moduleName].details[uid].elementId; delete instance[moduleName].details[uid]; Stratus.Instances.Clean(detailUid); } } function registerMapInstance(uid, $scope) { if (!Object.prototype.hasOwnProperty.call(instance, 'map')) { instance.map = {}; } instance.map[uid] = $scope; if (!Object.prototype.hasOwnProperty.call(instanceLink.Map, uid)) { instanceLink.Map[uid] = []; } } function registerDisclaimerInstance(uid, $scope) { if (!Object.prototype.hasOwnProperty.call(instance, 'disclaimer')) { instance.disclaimer = {}; } instance.disclaimer[uid] = $scope; if (!Object.prototype.hasOwnProperty.call(instanceLink.Disclaimer, uid)) { instanceLink.Disclaimer[uid] = []; } } function getDefaultWhereOptions() { return clone(defaultWhereOptions); } function getSearchInstanceLinks(searchUid, moduleName = 'property') { const linkedLists = []; if (Object.prototype.hasOwnProperty.call(instanceLink.Search, searchUid)) { instanceLink.Search[searchUid].forEach((listUid) => { if (Object.prototype.hasOwnProperty.call(instance[moduleName].list, listUid)) { linkedLists.push(instance[moduleName].list[listUid]); } }); } return linkedLists; } function getListInstance(listUid, moduleName = 'property') { return Object.prototype.hasOwnProperty.call(instanceLink.List, listUid) ? instance[moduleName].list[listUid] : null; } function getListInstanceLinks(listUid, moduleName = 'property') { const linkedSearches = []; if (Object.prototype.hasOwnProperty.call(instanceLink.List, listUid)) { instanceLink.List[listUid].forEach((searchUid) => { if (Object.prototype.hasOwnProperty.call(instance[moduleName].list, searchUid)) { linkedSearches.push(instance[moduleName].list[searchUid]); } }); } return linkedSearches; } function getDisclaimerInstance(disclaimerUid) { return disclaimerUid ? (Object.prototype.hasOwnProperty.call(instance.disclaimer, disclaimerUid) ? { [instance.disclaimer[disclaimerUid].elementId]: instance.disclaimer[disclaimerUid] } : null) : instance.disclaimer; } function setPageTitle(title) { if (!defaultPageTitle) { defaultPageTitle = JSON.parse(JSON.stringify($window.document.title)); } if (!title) { $window.document.title = defaultPageTitle; } else { $window.document.title = title; } } function getIdxServices() { return idxServicesEnabled; } function setIdxServices(services) { idxServicesEnabled = services; } function setTokenURL(url) { tokenRefreshURL = url; } function tokenKeepAuth(keepAlive = false) { return $q((resolve, reject) => __awaiter$b(this, void 0, void 0, function* () { try { if (Object.keys(session.services).length < 1 || session.expires < new Date(Date.now() + (5 * 1000))) { yield tokenRefresh(keepAlive, true); resolve(); } else { resolve(); } } catch (err) { console.error('tokenKeepAuth Error:', err); reject(err); } })); } function tokenRefresh(keepAlive = false, cacheReset = false) { return $q((resolve, reject) => { let additionalQueries = `&apiVersion=${apiVersion}`; if (idxServicesEnabled.length !== 0) { idxServicesEnabled.forEach((service) => { additionalQueries += `&service[]=${service}`; }); } if (cacheReset) { additionalQueries += '&cacheReset=true'; } $http({ method: 'GET', url: tokenRefreshURL + additionalQueries }).then((response) => { if (typeof response === 'object' && Object.prototype.hasOwnProperty.call(response, 'data') && Object.prototype.hasOwnProperty.call(response.data, 'services') && Object.prototype.hasOwnProperty.call(response.data.services, 'length')) { tokenHandleGoodResponse(response, keepAlive); resolve(); } else { reject(tokenHandleBadResponse(response)); } }, (response) => { reject(tokenHandleBadResponse(response)); }); }); } function tokenHandleGoodResponse(response, keepAlive = false) { session.services = {}; response.data.services.forEach((service) => { if (Object.prototype.hasOwnProperty.call(service, 'id')) { if (!Object.prototype.hasOwnProperty.call(service, 'fetchTime')) { service.fetchTime = { Property: null, Media: null, Member: null, Office: null, OpenHouse: null }; } if (!Object.prototype.hasOwnProperty.call(service, 'analyticsEnabled') || service.analyticsEnabled === null) { service.analyticsEnabled = []; } if (!Object.prototype.hasOwnProperty.call(service, 'logo') || service.logo === null) { service.logo = { default: null }; } if (!Object.prototype.hasOwnProperty.call(service, 'mandatoryLogo') || service.mandatoryLogo === null) { service.mandatoryLogo = []; } session.services[service.id] = service; session.lastCreated = new Date(service.created); session.lastTtl = service.ttl; session.expires = new Date(session.lastCreated.getTime() + (session.lastTtl - 15) * 1000); } }); if (Object.prototype.hasOwnProperty.call(response.data, 'contactUrl') && response.data.contactUrl !== '') { sharedValues.contactUrl = response.data.contactUrl; } if (Object.prototype.hasOwnProperty.call(response.data, 'contactCommentVariable') && response.data.contactCommentVariable !== '') { sharedValues.contactCommentVariable = response.data.contactCommentVariable; } if (Object.prototype.hasOwnProperty.call(response.data, 'contact')) { sharedValues.contact = { name: '', emails: {}, locations: {}, phones: {}, socialUrls: {}, urls: {}, }; if (Object.prototype.hasOwnProperty.call(response.data, 'site') && isString(response.data.site) && response.data.site !== '') { sharedValues.contact.name = response.data.site; } if (Object.prototype.hasOwnProperty.call(response.data, 'contactName') && isString(response.data.contactName) && response.data.site !== '') { sharedValues.contact.name = response.data.contactName; } if (Object.prototype.hasOwnProperty.call(response.data, 'contact') && isPlainObject(response.data.contact)) { if (Object.prototype.hasOwnProperty.call(response.data.contact, 'emails') && isPlainObject(response.data.contact.emails)) { sharedValues.contact.emails = response.data.contact.emails; } if (Object.prototype.hasOwnProperty.call(response.data.contact, 'locations') && isPlainObject(response.data.contact.locations)) { sharedValues.contact.locations = response.data.contact.locations; } if (Object.prototype.hasOwnProperty.call(response.data.contact, 'phones') && isPlainObject(response.data.contact.phones)) { sharedValues.contact.phones = response.data.contact.phones; } if (Object.prototype.hasOwnProperty.call(response.data.contact, 'socialUrls') && isPlainObject(response.data.contact.socialUrls)) { sharedValues.contact.socialUrls = response.data.contact.socialUrls; } if (Object.prototype.hasOwnProperty.call(response.data.contact, 'urls') && isPlainObject(response.data.contact.urls)) { sharedValues.contact.urls = response.data.contact.urls; } } } if (Object.prototype.hasOwnProperty.call(response.data, 'integrations')) { if (Object.prototype.hasOwnProperty.call(response.data.integrations, 'analytics')) { if (Object.prototype.hasOwnProperty.call(response.data.integrations.analytics, 'googleAnalytics')) { if (Object.prototype.hasOwnProperty.call(response.data.integrations.analytics.googleAnalytics, 'accountId') && isString(response.data.integrations.analytics.googleAnalytics.accountId) && response.data.integrations.analytics.googleAnalytics.accountId !== '') { sharedValues.integrations.analytics.googleAnalytics = { accountId: response.data.integrations.analytics.googleAnalytics.accountId }; } } if (Object.prototype.hasOwnProperty.call(response.data.integrations.analytics, 'listTrac')) { if (Object.prototype.hasOwnProperty.call(response.data.integrations.analytics.listTrac, 'accountId') && isString(response.data.integrations.analytics.listTrac.accountId) && response.data.integrations.analytics.listTrac.accountId !== '') { sharedValues.integrations.analytics.listTrac = { accountId: response.data.integrations.analytics.listTrac.accountId }; ListTrac.setAccountId(sharedValues.integrations.analytics.listTrac.accountId); } } } if (Object.prototype.hasOwnProperty.call(response.data.integrations, 'maps')) { if (Object.prototype.hasOwnProperty.call(response.data.integrations.maps, 'googleMaps')) { if (Object.prototype.hasOwnProperty.call(response.data.integrations.maps.googleMaps, 'publicKey') && isString(response.data.integrations.maps.googleMaps.publicKey) && response.data.integrations.maps.googleMaps.publicKey !== '') { sharedValues.integrations.maps.googleMaps = { publicKey: response.data.integrations.maps.googleMaps.publicKey }; } } } } if (!sessionInitialized) { emitManual('sessionInit', 'Idx', null); } emitManual('sessionRefresh', 'Idx', null); sessionInitialized = true; if (keepAlive) { tokenEnableRefreshTimer(); } } function tokenHandleBadResponse(response) { let errorMessage = 'Token supplied is invalid or blank'; if (typeof response === 'object' && Object.prototype.hasOwnProperty.call(response, 'data') && Object.prototype.hasOwnProperty.call(response.data, 'errors') && Object.prototype.hasOwnProperty.call(response.data.errors, 'length')) { errorMessage = response.data.errors; } $mdToast.show($mdToast.simple() .textContent('Unable to authorize Idx feed!') .toastClass('errorMessage') .position('top right') .hideDelay(5000)); return errorMessage; } function tokenEnableRefreshTimer() { clearTimeout(refreshLoginTimer); refreshLoginTimer = setTimeout(() => __awaiter$b(this, void 0, void 0, function* () { yield tokenRefresh(); }), (session.lastTtl - 15) * 1000); } function updateFetchTime(apiFetch, modelName, serviceId) { const fetchTime = apiFetch.header.get('x-fetch-time'); if (fetchTime) { const oldTime = session.services[serviceId].fetchTime[modelName]; session.services[serviceId].fetchTime[modelName] = new Date(fetchTime); if (!(isDate(oldTime) && isDate(session.services[serviceId].fetchTime[modelName])) || oldTime.getTime() !== session.services[serviceId].fetchTime[modelName].getTime()) { emitManual('fetchTimeUpdate', 'Idx', null, serviceId, modelName, session.services[serviceId].fetchTime[modelName]); } } } function createModel(request) { if (request.api && !isString(request.api)) { request.api.apiVersion = apiVersion; } const model = new Model(request); if (Object.prototype.hasOwnProperty.call(request, 'api') && request.api) { model.meta.set('api', isJSON(request.api) ? JSON.parse(request.api) : request.api); } if (Object.prototype.hasOwnProperty.call(request, 'serviceId')) { model.serviceId = request.serviceId; } return model; } function createCollection(request) { request.direct = true; if (request.api) { request.api.apiVersion = apiVersion; } const collection = new Collection(request); if (request.api) { collection.meta.set('api', isJSON(request.api) ? JSON.parse(request.api) : request.api); } return collection; } function fetchMergeCollections(originalCollection, collections, modelName, append = false) { return __awaiter$b(this, void 0, void 0, function* () { originalCollection.pending = true; originalCollection.completed = false; let maxCount = 0; let totalCount = 0; const fetchPromises = []; collections.forEach(collection => { const options = {}; if (session.services[collection.serviceId].token !== null) { options.headers = { Authorization: session.services[collection.serviceId].token }; } fetchPromises.push($q((resolve) => __awaiter$b(this, void 0, void 0, function* () { yield collection.fetch('POST', null, options); yield modelInjectProperty(collection.models, { _ServiceId: collection.serviceId }); updateFetchTime(collection, modelName, collection.serviceId); const maxRecords = collection.header.get('x-max-count'); const countRecords = collection.header.get('x-total-count'); if (maxRecords) { maxCount += parseInt(maxRecords, 10); } if (countRecords) { totalCount += parseInt(countRecords, 10); if (!maxRecords) { maxCount += parseInt(countRecords, 10); } } resolve(collection.models); }))); }); if (!append) { originalCollection.models.splice(0, originalCollection.models.length); } return $q.all(fetchPromises) .then((fetchedData) => __awaiter$b(this, void 0, void 0, function* () { yield $q.all(fetchedData.map((models) => { if (isArray(models)) { originalCollection.models.push(...models); } })); return originalCollection; })) .then(() => { originalCollection.header.set('x-max-count', maxCount); originalCollection.header.set('x-total-count', totalCount); originalCollection.meta.set('fetchDate', new Date()); originalCollection.pending = false; originalCollection.completed = true; originalCollection.filtering = false; originalCollection.paginate = false; return originalCollection; }); }); } function fetchReplaceModel(originalModel, newModel, modelName) { return __awaiter$b(this, void 0, void 0, function* () { originalModel.pending = true; originalModel.completed = false; const fetchPromises = []; const options = {}; if (session.services[newModel.serviceId].token !== null) { options.headers = { Authorization: session.services[newModel.serviceId].token }; } fetchPromises.push($q((resolve) => __awaiter$b(this, void 0, void 0, function* () { yield newModel.fetch('POST', null, options); yield modelInjectProperty([newModel.data], { _ServiceId: newModel.serviceId }); updateFetchTime(newModel, modelName, newModel.serviceId); resolve(newModel.data); }))); const fetchedData = yield $q.all(fetchPromises); yield $q.all(fetchedData.map((data) => { originalModel.data = data; })); originalModel.meta.set('fetchDate', new Date()); originalModel.pending = false; originalModel.completed = true; return originalModel; }); } function modelInjectProperty(modelDatas, properties) { return $q.all(modelDatas.map((modelData) => { extend(modelData, properties); })); } function createOrSyncCollectionVariable(uid, moduleName, scopedCollectionVarName) { let collection; Object.keys(instance[moduleName].list).forEach(listName => { if (!collection && listName === uid && Object.prototype.hasOwnProperty.call(instance[moduleName].list, listName) && Object.prototype.hasOwnProperty.call(instance[moduleName].list[listName], scopedCollectionVarName) && instance[moduleName].list[listName][scopedCollectionVarName] instanceof Collection) { collection = instance[moduleName].list[listName][scopedCollectionVarName]; } }); if (!collection) { collection = new Collection(); } Object.keys(instance[moduleName].list).forEach(listName => { if (listName === uid && (!Object.prototype.hasOwnProperty.call(instance[moduleName].list[listName], scopedCollectionVarName) || instance[moduleName].list[listName][scopedCollectionVarName] !== collection)) { instance[moduleName].list[listName][scopedCollectionVarName] = collection; } }, this); return collection; } function compileGenericWhereFilter(where, searchPossibilities) { const whereQuery = {}; const andStatement = []; const searchFunctions = { valueEquals: (searchObject, value) => { whereQuery[searchObject.apiField] = value; }, stringLike: (searchObject, value) => { if (!isEmpty(value)) { whereQuery[searchObject.apiField] = { like: value, options: 'i' }; } }, stringLikeArray: (searchObject, value) => { value = typeof value === 'string' ? [value] : value; if (value.length > 1) { const stringLikeArrayOrStatement = []; value.forEach((requestedValue) => { if (!isEmpty(requestedValue)) { stringLikeArrayOrStatement.push({ [searchObject.apiField]: { like: requestedValue, options: 'i' } }); } }); if (!isEmpty(stringLikeArrayOrStatement)) { andStatement.push({ or: stringLikeArrayOrStatement }); } } else if (value.length === 1) { if (!isEmpty(value[0])) { whereQuery[searchObject.apiField] = { like: value[0], options: 'i' }; } } }, stringIncludesArray: (searchObject, value) => { value = typeof value === 'string' ? [value] : value; if (value.length > 1) { whereQuery[searchObject.apiField] = { inq: value }; } else if (value.length === 1) { whereQuery[searchObject.apiField] = value[0]; } }, stringIncludesArrayAlternative: (searchObject, value) => { value = typeof value === 'string' ? [value] : value; if (value.length > 1) { whereQuery[searchObject.apiField] = { in: value }; } else if (value.length === 1) { whereQuery[searchObject.apiField] = value[0]; } }, numberEqualGreater: (searchObject, value) => { if (value && value !== 0) { if (Object.prototype.hasOwnProperty.call(whereQuery, searchObject.apiField) && Object.prototype.hasOwnProperty.call(whereQuery[searchObject.apiField], 'lte')) { whereQuery[searchObject.apiField] = { between: [ parseInt(value, 10), parseInt(get(whereQuery[searchObject.apiField], 'lte'), 10) ] }; } else { whereQuery[searchObject.apiField] = { gte: parseInt(value, 10) }; } } }, numberEqualLess: (searchObject, value) => { if (value && value !== 0) { if (Object.prototype.hasOwnProperty.call(whereQuery, searchObject.apiField) && Object.prototype.hasOwnProperty.call(whereQuery[searchObject.apiField], 'gte')) { whereQuery[searchObject.apiField] = { between: [ parseInt(get(whereQuery[searchObject.apiField], 'gte'), 10), parseInt(value, 10) ] }; } else { whereQuery[searchObject.apiField] = { lte: parseInt(value, 10) }; } } }, andOr: (searchObject, value) => { if (Object.prototype.hasOwnProperty.call(searchObject, 'andOr')) { const andOrOrStatement = []; searchObject.andOr.forEach((orObject) => { if (orObject.type === 'valueEquals') { andOrOrStatement.push({ [orObject.apiField]: value }); } else if (orObject.type === 'stringLike') { if (!isEmpty(value)) { andOrOrStatement.push({ [orObject.apiField]: { like: value, options: 'i' } }); } } else if (orObject.type === 'stringLikeArray') { value = typeof value === 'string' ? [value] : value; if (value.length > 1) { value.forEach((requestedValue) => { if (!isEmpty(requestedValue)) { andOrOrStatement.push({ [orObject.apiField]: { like: requestedValue, options: 'i' } }); } }); } else if (value.length === 1) { if (!isEmpty(value[0])) { andOrOrStatement.push({ [orObject.apiField]: { like: value[0], options: 'i' } }); } } } else if (orObject.type === 'stringIncludesArray') { value = typeof value === 'string' ? [value] : value; if (value.length > 1) { andOrOrStatement.push({ [orObject.apiField]: { inq: value } }); } else if (value.length === 1) { andOrOrStatement.push({ [orObject.apiField]: value[0] }); } } }); if (!isEmpty(andOrOrStatement)) { if (andOrOrStatement.length > 1) { andStatement.push({ or: andOrOrStatement }); } else if (andOrOrStatement.length === 1) { andStatement.push(andOrOrStatement[0]); } } } } }; for (const [widgetField, searchObject] of Object.entries(searchPossibilities)) { if (!Object.prototype.hasOwnProperty.call(searchObject, 'apiField')) { searchObject.apiField = widgetField; } if (Object.prototype.hasOwnProperty.call(searchFunctions, searchObject.type) && Object.prototype.hasOwnProperty.call(where, widgetField) && where[widgetField] !== '') { searchFunctions[searchObject.type](searchObject, where[widgetField]); } } if (!isEmpty(andStatement)) { whereQuery.and = andStatement; } return whereQuery; } function compilePropertyWhereFilter(where) { return compileGenericWhereFilter(where, { ListingKey: { type: 'valueEquals' }, ListingId: { type: 'stringIncludesArray' }, ListingType: { type: 'stringIncludesArray' }, Status: { type: 'stringIncludesArray' }, ListPriceMin: { type: 'numberEqualGreater', apiField: '_BestPrice' }, ListPriceMax: { type: 'numberEqualLess', apiField: '_BestPrice' }, Bathrooms: { type: 'numberEqualGreater' }, Bedrooms: { type: 'numberEqualGreater', apiField: 'BedroomsTotal' }, AgentLicense: { type: 'stringIncludesArray' }, OfficeNumber: { type: 'stringIncludesArray' }, OfficeName: { type: 'stringIncludesArray' }, OpenHouseOnly: { type: 'valueEquals' }, UnparsedAddress: { type: 'stringLikeArray' }, StreetAddress: { apiField: '_StreetAddress', type: 'stringLikeArray' }, eStreetAddress: { apiField: '_StreetAddress', type: 'stringIncludesArray' }, City: { type: 'stringLikeArray' }, eCity: { apiField: 'City', type: 'stringIncludesArray' }, PostalCode: { type: 'stringIncludesArray' }, CountyOrParish: { type: 'stringLikeArray' }, eCountyOrParish: { apiField: 'CountyOrParish', type: 'stringIncludesArray' }, SubdivisionName: {