Skip to content

Commit 90fa0a3

Browse files
authored
Merge pull request #371 from LordJavi/fix-arearestrictions-search
Fix arearestrictions search
2 parents 91d4c5f + d097637 commit 90fa0a3

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

src/data/map.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,12 +1178,13 @@ const getPortals = async (minLat, maxLat, minLon, maxLon, portalFilterExclude =
11781178
};
11791179

11801180
/* eslint-disable no-case-declarations */
1181-
const getSearchData = async (lat, lon, id, value, iconStyle) => {
1181+
const getSearchData = async (lat, lon, id, value, iconStyle, areaRestrictions) => {
11821182
let sql = '';
11831183
let args = [lat, lon, lat];
11841184
let useDb;
11851185
let conditions = [];
11861186
let sanitizedValue = sanitizer.sanitize(value);
1187+
let areaRestrictionsSQL = getAreaRestrictionSql(areaRestrictions);
11871188
sanitizedValue = sanitizedValue.toLowerCase();
11881189
switch (id) {
11891190
case 'search-reward':
@@ -1308,7 +1309,7 @@ const getSearchData = async (lat, lon, id, value, iconStyle) => {
13081309
useDb = 'pokestop';
13091310
break;
13101311
}
1311-
sql += ` ORDER BY distance LIMIT ${config.searchMaxResults || 20}`;
1312+
sql += `${areaRestrictionsSQL} ORDER BY distance LIMIT ${config.searchMaxResults || 20}`;
13121313
let results = await dbSelection(useDb).query(sql, args);
13131314
if (results && results.length > 0) {
13141315
switch (id) {

src/routes/api.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ router.post('/get_data', async (req, res) => {
1919
});
2020

2121
router.post('/search', async (req, res) => {
22-
const data = await getSearch(req.body);
22+
const data = await getSearch(req.session.perms, req.body);
2323
res.json({ data: data });
2424
});
2525

@@ -1051,8 +1051,9 @@ const getData = async (perms, filter) => {
10511051
return data;
10521052
};
10531053

1054-
const getSearch = async (filter) => {
1055-
const searchData = await map.getSearchData(filter.lat, filter.lon, filter.id, filter.value, filter.icon_style);
1054+
const getSearch = async (perms, filter) => {
1055+
const permAreaRestrictions = perms ? perms.areaRestrictions : [];
1056+
const searchData = await map.getSearchData(filter.lat, filter.lon, filter.id, filter.value, filter.icon_style, permAreaRestrictions);
10561057
return searchData;
10571058
};
10581059

0 commit comments

Comments
 (0)