|
|
@@ -5,8 +5,11 @@ exports = module.exports = {
|
|
|
};
|
|
|
|
|
|
var request = require('request'),
|
|
|
+ wikijs = require('wikijs').default,
|
|
|
yelp = require('yelp-fusion');
|
|
|
|
|
|
+var wiki = wikijs();
|
|
|
+
|
|
|
var YELP_CLIENTID = 'VMEhsiPTvZni4eGAFSaPeA';
|
|
|
var YELP_APIKEY = 'uN7lv_ywa-5osEguCmaGeE8vnGKZezJO3c2-ADLd1ySCPcGTWiK71XwdgvGNeavvw04Yc84rHaJzkSAhvNmFubQ5zyMAsdR0gCuLpVFhqHXTshl67BdbDO6WYSYlXHYx';
|
|
|
|
|
|
@@ -23,41 +26,63 @@ function search(req, res, next) {
|
|
|
const lat = req.query.lat;
|
|
|
const lon = req.query.lon;
|
|
|
|
|
|
- function amendDetails(results) {
|
|
|
- results.forEach(function (r) {
|
|
|
+ function translateSearchResultItems(results) {
|
|
|
+ var classBusiness = [
|
|
|
+ 'fast_food',
|
|
|
+ 'restaurant',
|
|
|
+ 'pub',
|
|
|
+ 'bar',
|
|
|
+ 'hotel',
|
|
|
+ 'hostel',
|
|
|
+ 'supermarket',
|
|
|
+ 'retail'
|
|
|
+ ];
|
|
|
+
|
|
|
+ return results.map(function (r) {
|
|
|
+ var tmp = {
|
|
|
+ icon: 'fa-address-card',
|
|
|
+ address: r.address,
|
|
|
+ lat: r.lat,
|
|
|
+ lon: r.lon,
|
|
|
+ type: r.type,
|
|
|
+ class: classBusiness.indexOf(r.type) !== -1 ? 'business' : '',
|
|
|
+ display_name: r.display_name
|
|
|
+ };
|
|
|
+
|
|
|
// icons
|
|
|
- r.icon = 'fa-address-card';
|
|
|
- if (r.type === 'fast_food' || r.type === 'restaurant') r.icon = 'fa-utensils';
|
|
|
- if (r.type === 'doctors') r.icon = 'fa-user-md';
|
|
|
- if (r.type === 'beach') r.icon = 'fa-umbrella-beach';
|
|
|
- if (r.type === 'dentist') r.icon = 'fa-tooth';
|
|
|
- if (r.type === 'car') r.icon = 'fa-car';
|
|
|
- if (r.type === 'playground') r.icon = 'fa-child';
|
|
|
- if (r.type === 'recreation_ground') r.icon = 'fa-running';
|
|
|
- if (r.type === 'sports_centre' || r.type === 'pitch') r.icon = 'fa-futbol';
|
|
|
- if (r.type === 'bicycle-rental') r.icon = 'fa-bicycle';
|
|
|
- if (r.type === 'school') r.icon = 'fa-graduation-cap';
|
|
|
- if (r.type === 'post_box' || r.type === 'post_office') r.icon = 'fa-envelope-square';
|
|
|
- if (r.type === 'canal' || r.type === 'river' || r.type === 'water') r.icon = 'fa-water';
|
|
|
- if (r.type === 'station' || r.type === 'stop') r.icon = 'fa-subway';
|
|
|
- if (r.type === 'attraction') r.icon = 'fa-monument';
|
|
|
- if (r.type === 'city' || r.type === 'village' || r.type === 'administrative') r.icon = 'fa-city';
|
|
|
- if (r.type === 'administrative' || r.class === 'office') r.icon = 'fa-building';
|
|
|
- if (r.type === 'pub' || r.type === 'bar') r.icon = 'fa-beer';
|
|
|
- if (r.type === 'hotel' || r.type === 'hostel') r.icon = 'fa-bed';
|
|
|
- if (r.type === 'supermarket' || r.type === 'retail') r.icon = 'fa-shopping-cart';
|
|
|
+ if (r.type === 'fast_food' || r.type === 'restaurant') tmp.icon = 'fa-utensils';
|
|
|
+ if (r.type === 'doctors') tmp.icon = 'fa-user-md';
|
|
|
+ if (r.type === 'beach') tmp.icon = 'fa-umbrella-beach';
|
|
|
+ if (r.type === 'dentist') tmp.icon = 'fa-tooth';
|
|
|
+ if (r.type === 'car') tmp.icon = 'fa-car';
|
|
|
+ if (r.type === 'playground') tmp.icon = 'fa-child';
|
|
|
+ if (r.type === 'recreation_ground') tmp.icon = 'fa-running';
|
|
|
+ if (r.type === 'sports_centre' || r.type === 'pitch') tmp.icon = 'fa-futbol';
|
|
|
+ if (r.type === 'bicycle-rental') tmp.icon = 'fa-bicycle';
|
|
|
+ if (r.type === 'school') tmp.icon = 'fa-graduation-cap';
|
|
|
+ if (r.type === 'post_box' || r.type === 'post_office') tmp.icon = 'fa-envelope-square';
|
|
|
+ if (r.type === 'canal' || r.type === 'river' || r.type === 'water') tmp.icon = 'fa-water';
|
|
|
+ if (r.type === 'station' || r.type === 'stop') tmp.icon = 'fa-subway';
|
|
|
+ if (r.type === 'attraction') tmp.icon = 'fa-monument';
|
|
|
+ if (r.type === 'city' || r.type === 'village' || r.type === 'administrative') tmp.icon = 'fa-city';
|
|
|
+ if (r.type === 'administrative' || r.class === 'office') tmp.icon = 'fa-building';
|
|
|
+ if (r.type === 'pub' || r.type === 'bar') tmp.icon = 'fa-beer';
|
|
|
+ if (r.type === 'hotel' || r.type === 'hostel') tmp.icon = 'fa-bed';
|
|
|
+ if (r.type === 'supermarket' || r.type === 'retail') tmp.icon = 'fa-shopping-cart';
|
|
|
|
|
|
// ensure we have some city if only town is mentioned
|
|
|
- if (!r.address.city) r.address.city = r.address.town;
|
|
|
+ if (!tmp.address.city) tmp.address.city = tmp.address.town;
|
|
|
|
|
|
// name
|
|
|
- r.name = r.display_name.split(',')[0];
|
|
|
- if (r.class === 'place' || r.class === 'building') r.name = r.address.road + ' ' + r.address.house_number;
|
|
|
- if (r.type === 'city') r.name = r.address.city;
|
|
|
- if (!r.name) r.name = r.display_name;
|
|
|
- });
|
|
|
+ tmp.name = r.display_name.split(',')[0];
|
|
|
+ if (r.class === 'place' || r.class === 'building') tmp.name = r.address.road + ' ' + r.address.house_number;
|
|
|
+ if (r.type === 'city') tmp.name = r.address.city;
|
|
|
+
|
|
|
+ // fallback to display name
|
|
|
+ if (!tmp.name) tmp.name = r.display_name;
|
|
|
|
|
|
- return results;
|
|
|
+ return tmp;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
function removeDuplicates(results) {
|
|
|
@@ -89,7 +114,7 @@ function search(req, res, next) {
|
|
|
function noLocationSearch() {
|
|
|
query(null, function (result) {
|
|
|
result = removeDuplicates(result);
|
|
|
- res.status(200).send(amendDetails(result));
|
|
|
+ res.status(200).send(translateSearchResultItems(result));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -112,16 +137,16 @@ function search(req, res, next) {
|
|
|
|
|
|
query(position.address.city + ' , ' + position.address.country, function (result) {
|
|
|
results = removeDuplicates(results.concat(result));
|
|
|
- if (results.length >= 20) return res.status(200).send(amendDetails(results));
|
|
|
+ if (results.length >= 20) return res.status(200).send(translateSearchResultItems(results));
|
|
|
|
|
|
query(position.address.country, function (result) {
|
|
|
results = removeDuplicates(results.concat(result));
|
|
|
- if (results.length >= 20) return res.status(200).send(amendDetails(results));
|
|
|
+ if (results.length >= 20) return res.status(200).send(translateSearchResultItems(results));
|
|
|
|
|
|
query(null, function (result) {
|
|
|
results = removeDuplicates(results.concat(result));
|
|
|
|
|
|
- return res.status(200).send(amendDetails(results));
|
|
|
+ return res.status(200).send(translateSearchResultItems(results));
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
@@ -133,20 +158,45 @@ function details(req, res, next) {
|
|
|
const name = req.query.name;
|
|
|
const lat = req.query.lat;
|
|
|
const lon = req.query.lon;
|
|
|
-
|
|
|
- yelpClient.search({
|
|
|
- term: name,
|
|
|
- latitude: lat,
|
|
|
- longitude: lon
|
|
|
- }).then(response => {
|
|
|
- if (!response.jsonBody.businesses[0]) return res.status(200).send({});
|
|
|
-
|
|
|
- yelpClient.business(response.jsonBody.businesses[0].id).then(response => {
|
|
|
- res.status(200).send(response.jsonBody);
|
|
|
+ const itemClass = req.query.class;
|
|
|
+
|
|
|
+ if (itemClass === 'business') {
|
|
|
+ yelpClient.search({
|
|
|
+ term: name,
|
|
|
+ latitude: lat,
|
|
|
+ longitude: lon
|
|
|
+ }).then(response => {
|
|
|
+ if (!response.jsonBody.businesses[0]) return res.status(200).send({});
|
|
|
+
|
|
|
+ yelpClient.business(response.jsonBody.businesses[0].id).then(response => {
|
|
|
+ res.status(200).send(response.jsonBody);
|
|
|
+ }).catch(e => {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
}).catch(e => {
|
|
|
console.log(e);
|
|
|
});
|
|
|
- }).catch(e => {
|
|
|
- console.log(e);
|
|
|
- });
|
|
|
+ } else {
|
|
|
+ wiki.find(name).then(function (page) {
|
|
|
+ page.info().then(function (info) {
|
|
|
+ info.url = page.raw.fullurl;
|
|
|
+
|
|
|
+ page.summary().then(function (summary) {
|
|
|
+ page.mainImage().then(function (mainImage) {
|
|
|
+ info.photo = mainImage;
|
|
|
+ info.summary = summary;
|
|
|
+ res.status(200).send(info);
|
|
|
+ }).catch(function (e) {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ }).catch(function (e) {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ }).catch(function (e) {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ }).catch(function (e) {
|
|
|
+ console.log(e);
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|