Skip to content

Commit

Permalink
fix: ensure only enabled make it through
Browse files Browse the repository at this point in the history
  • Loading branch information
TurtIeSocks committed Nov 2, 2023
1 parent fe63f27 commit d98c6f1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
23 changes: 19 additions & 4 deletions server/src/models/Gym.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ class Gym extends Model {
return 'gym'
}

/**
*
* @param {import('objection').QueryBuilder<Gym, Gym[]>} query
* @param {boolean} isMad
*/
static onlyValid(query, isMad) {
query.andWhere('enabled', true)
if (!isMad) {
query.andWhere('deleted', false)
}
}

static async getAll(perms, args, { isMad, availableSlotsCol }, userId) {
const {
gyms: gymPerms,
Expand Down Expand Up @@ -118,7 +130,7 @@ class Gym extends Model {
query
.whereBetween(isMad ? 'latitude' : 'lat', [args.minLat, args.maxLat])
.andWhereBetween(isMad ? 'longitude' : 'lon', [args.minLon, args.maxLon])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
Gym.onlyValid(query, isMad)

const raidBosses = new Set()
const raidForms = new Set()
Expand Down Expand Up @@ -459,7 +471,6 @@ class Gym extends Model {
'url',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.whereRaw(`LOWER(name) LIKE '%${search}%'`)
.limit(searchResultsLimit)
.orderBy('distance')
Expand All @@ -469,6 +480,8 @@ class Gym extends Model {
if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) {
return []
}
Gym.onlyValid(query, isMad)

return query
}

Expand Down Expand Up @@ -507,7 +520,6 @@ class Gym extends Model {
'>=',
isMad ? this.knex().fn.now() : ts,
)
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query
.leftJoin('gymdetails', 'gym.gym_id', 'gymdetails.gym_id')
Expand All @@ -519,6 +531,8 @@ class Gym extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Gym.onlyValid(query, isMad)

return query
}

Expand Down Expand Up @@ -585,7 +599,6 @@ class Gym extends Model {
minLon - wiggle,
maxLon + wiggle,
])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query.select(['gym_id AS id', 'latitude AS lat', 'longitude AS lon'])
} else {
Expand All @@ -600,6 +613,8 @@ class Gym extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Gym.onlyValid(query, isMad)

const results = await query
return results
}
Expand Down
26 changes: 21 additions & 5 deletions server/src/models/Pokestop.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ class Pokestop extends Model {
return 'pokestop'
}

/**
*
* @param {import('objection').QueryBuilder<Pokestop, Pokestop[]>} query
* @param {boolean} isMad
*/
static onlyValid(query, isMad) {
query.andWhere('enabled', true)
if (!isMad) {
query.andWhere('deleted', false)
}
}

static async getAll(
perms,
args,
Expand Down Expand Up @@ -176,7 +188,8 @@ class Pokestop extends Model {
query
.whereBetween(isMad ? 'latitude' : 'lat', [args.minLat, args.maxLat])
.andWhereBetween(isMad ? 'longitude' : 'lon', [args.minLon, args.maxLon])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)

Pokestop.onlyValid(query, isMad)
if (!getAreaSql(query, areaRestrictions, onlyAreas, isMad)) {
return []
}
Expand Down Expand Up @@ -1557,13 +1570,13 @@ class Pokestop extends Model {
isMad ? 'image AS url' : 'url',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.whereRaw(`LOWER(name) LIKE '%${search}%'`)
.limit(searchResultsLimit)
.orderBy('distance')
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)
return query
}

Expand Down Expand Up @@ -1606,7 +1619,6 @@ class Pokestop extends Model {
isMad ? 'quest_reward AS quest_rewards' : 'quest_rewards',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.andWhere('quest_timestamp', '>=', midnight || 0)
.andWhere((quests) => {
quests
Expand All @@ -1628,6 +1640,8 @@ class Pokestop extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)

const results = await query
const mapped = results.map((q) => ({ ...q, with_ar: q.with_ar ?? true }))

Expand Down Expand Up @@ -1697,7 +1711,6 @@ class Pokestop extends Model {
: 'lure_expire_timestamp',
distance,
])
.where(isMad ? 'enabled' : 'deleted', isMad)
.andWhere(
isMad ? 'lure_expiration' : 'lure_expire_timestamp',
'>=',
Expand All @@ -1709,6 +1722,8 @@ class Pokestop extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)

const results = await query
return results
}
Expand Down Expand Up @@ -1740,7 +1755,6 @@ class Pokestop extends Model {
minLon - 0.025,
maxLon + 0.025,
])
.andWhere(isMad ? 'enabled' : 'deleted', isMad)
if (isMad) {
query.select(['pokestop_id AS id', 'latitude AS lat', 'longitude AS lon'])
} else {
Expand All @@ -1757,6 +1771,8 @@ class Pokestop extends Model {
if (!getAreaSql(query, perms.areaRestrictions, onlyAreas, isMad)) {
return []
}
Pokestop.onlyValid(query, isMad)

return query
}
}
Expand Down

0 comments on commit d98c6f1

Please sign in to comment.