Model for review subjects, including metadata such as URLs, author names, business hours, etc.
- Source:
Methods
(protected, static) _isValidURL(url) → {Boolean}
Parameters:
Name | Type | Description |
---|---|---|
url |
String | URL to check |
- Source:
Throws:
-
if invalid
- Type
- ReportedError
Returns:
true if valid
- Type
- Boolean
(static) getLabel(thing, language) → {String}
Get label for a given thing in the provided language, or fall back to a prettified URL.
Parameters:
Name | Type | Description |
---|---|---|
thing |
Thing | the thing object to get a label for |
language |
String | the language code of the preferred language |
- Source:
Returns:
the best available label
- Type
- String
(async, static) getWithData(id, optionsopt) → {Thing}
Get a Thing object by ID, plus some of the data linked to it.
Parameters:
Name | Type | Attributes | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
id |
String | the unique ID of the Thing object |
|||||||||||||
options |
Object |
<optional> |
which data to include Properties
|
- Source:
Returns:
the Thing object
- Type
- Thing
(static) lookupByURL(url, userIDopt) → {Query}
Find a Thing object using a URL. May return multiple matches (but ordinarily should not).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
String | the URL to look up |
|
userID |
String |
<optional> |
include any review(s) of this thing by the given user |
- Source:
Returns:
query for current revisions that contain this URL
- Type
- Query
addFile(file)
Simple helper method to initialize files array for a Thing object if it does not exist already, and then add a file.
Parameters:
Name | Type | Description |
---|---|---|
file |
File | File object to add |
- Source:
(async) addFilesByIDsAndSave(files, userIDopt)
Obtain file objects for an array of file IDs, and associate them with this thing. Saves.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
files |
Array.<String> | IDs of the files to add |
|
userID |
String |
<optional> |
if given, uploader must match this user ID. Mismatches are silently ignored. |
- Source:
(async) getAverageStarRating() → {Number}
Calculate the average review rating for this Thing object
- Source:
Returns:
average rating, not rounded
- Type
- Number
(async) getReviewCount() → {Number}
Count the number of reviews associated with this Thing object (discounting old/deleted revisions).
- Source:
Returns:
the number of reviews
- Type
- Number
(async) getReviewsByUser(user) → {Array}
Get all reviews by the given user for this thing. The number is typically 1, but there may be edge cases or bugs where a user will have multiple reviews for the same thing.
Parameters:
Name | Type | Description |
---|---|---|
user |
User | the user whose reviews we're looking up for this thing |
- Source:
Returns:
array of the reviews
- Type
- Array
initializeFieldsFromAdapter(adapterResult)
Initialize field values from the lookup result of an adapter. Each adapter has a whitelist of supported fields which we check against before assigning values to the thing instance.
This function does not save and can therefore run synchronously. It resets all sync settings (whether a sync for a given field is active or not), so it should only be invoked on new Thing objects.
Silently ignores empty results.
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
adapterResult |
Object | the result from any backend adapter Properties
|
- Source:
Throws:
on malformed adapterResult object
(async) populateReviewMetrics() → {Thing}
Set this Thing object's virtual data fields for review metrics (performs table lookups, hence asynchronous). Does not save.
- Source:
Returns:
the modified thing object
- Type
- Thing
populateUserInfo(user)
Populate virtual permission fields in a Thing object with the rights of a given user.
Parameters:
Name | Type | Description |
---|---|---|
user |
User | the user whose permissions to check |
- Source:
setURLs(urls)
Update URLs and reset a Thing object's synchronization settings, based on which adapters report that they can retrieve external metadata for a given URL. Does not save.
Parameters:
Name | Type | Description |
---|---|---|
urls |
Array.<String> | the complete array of URLs to assign (previously assigned URLs will be overwritten) |
- Source:
(async) updateActiveSyncs(userID) → {Thing}
Fetch new external data for all fields set to be synchronized. Saves.
- Does not create a new revision, so if you need one, create it first.
- Performs search index update.
- Resolves with updated thing object.
- May result in a slug update, so if initiated by a user, should be passed the user ID. Otherwise, any slug changes will be without attribution
Parameters:
Name | Type | Description |
---|---|---|
userID |
String | the user to associate with any slug changes |
- Source:
Returns:
the updated thing
- Type
- Thing
(protected, inner) _organizeDataBySource(results) → {Object}
Put valid data from results array into an object with sourceID as the key and data as a reverse-order array. There may be multiple URLs from one source, assigning value to the same field. URLs earlier in the original thing.urls array take priority, so we have to ensure they come last.
Parameters:
Name | Type | Description |
---|---|---|
results |
Array.<Object> | results from multiple adapters |
- Source:
Returns:
key = source, value = array of data objects
- Type
- Object