Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

allow custom eventsFields #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ Non-mandatory parameters
* `since`: The start of the range to filter results. Format is Unix timestamp or `strtotime` data value, as accepted by [FB Graph API](https://developers.facebook.com/docs/graph-api/using-graph-api#time).
* `until`: The end of the range to filter results.
* `showActiveOnly`: Whether only non-cancelled, non-draft Events should be shown. Format is `boolean`. Default is `true`.
* `eventsFields`: The list of fields you want returned on the events. This defaults to the most common fields needed.

### Location/Place data in the query result

Expand Down
10 changes: 9 additions & 1 deletion lib/eventSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ EventSearch.prototype.search = function (options) {
queryOptions.since = options.since || (new Date().getTime()/1000).toFixed();
queryOptions.until = options.until || null;
queryOptions.showActiveOnly = options.showActiveOnly || true;
queryOptions.eventsFields = options.eventsFields || null;

function validateCategories (categories) {
var validCategories = [];
Expand Down Expand Up @@ -168,6 +169,13 @@ EventSearch.prototype.search = function (options) {
}
});
}

if (queryOptions.eventsFields) {
queryOptions.eventsFields.forEach(function(field) {
eventResultObj[field] = event[field];
});
}

var venueDistance = (venue.location && venue.location.latitude && venue.location.longitude ? parseInt((self.haversineDistance([venue.location.latitude, venue.location.longitude], [queryOptions.latitude, queryOptions.longitude], false)*1000).toFixed()) : null);
eventResultObj.id = event.id;
eventResultObj.name = event.name;
Expand Down Expand Up @@ -298,7 +306,7 @@ EventSearch.prototype.search = function (options) {

//Create a Graph API request array (promisified)
ids.forEach(function(idArray, index, arr) {
var eventsFields = [
var eventsFields = queryOptions.eventsFields || [
"id",
"type",
"name",
Expand Down
2 changes: 0 additions & 2 deletions schema/events-response.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,9 @@
"required": [
"id",
"name",
"distance",
"startTime",
"timeFromNow",
"distances",
"stats",
"venue"
],
"additionalProperties": false
Expand Down