mirror of https://github.com/pelias/api.git
Lily He
7 years ago
9 changed files with 89 additions and 20 deletions
@ -1,5 +1,13 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:has_request_errors'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
module.exports = (request, response) => { |
||||
return _.get(request, 'errors', []).length > 0; |
||||
module.exports = (req, res) => { |
||||
const has_request_errors = _.get(req, 'errors', []).length > 0; |
||||
debugLog.push(req, () => ({ |
||||
reply: has_request_errors, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return has_request_errors; |
||||
}; |
||||
|
@ -1,4 +1,15 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:has_request_parameter'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
// returns true IFF req.clean has a key with the supplied name
|
||||
module.exports = (parameter) => (req, res) => (_.has(req, ['clean', parameter])); |
||||
module.exports = (parameter) => (req, res) => { |
||||
const has_request_parameter = _.has(req, ['clean', parameter]); |
||||
|
||||
debugLog.push(req, () => ({ |
||||
reply: {[parameter]: has_request_parameter}, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return has_request_parameter; |
||||
}; |
||||
|
@ -1,5 +1,13 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:has_response_data'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
module.exports = (request, response) => { |
||||
return _.get(response, 'data', []).length > 0; |
||||
const has_response_data = _.get(response, 'data', []).length > 0; |
||||
debugLog.push(request, () => ({ |
||||
reply: has_response_data, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return has_response_data; |
||||
}; |
||||
|
@ -1,4 +1,14 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:is_addressit_parse'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
// returns true IFF req.clean.parser is addressit
|
||||
module.exports = (req, res) => (_.get(req, 'clean.parser') === 'addressit'); |
||||
module.exports = (req, res) => { |
||||
const is_addressit_parse = _.get(req, 'clean.parser') === 'addressit'; |
||||
debugLog.push(req, () => ({ |
||||
reply: is_addressit_parse, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return is_addressit_parse; |
||||
}; |
||||
|
@ -1,18 +1,22 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:is_admin_only_analysis'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
module.exports = (request, response) => { |
||||
if (!request.clean.hasOwnProperty('parsed_text')) { |
||||
debugLog.push(request, false + '(no parsed_text)'); |
||||
debugLog.push(request, false + ' (no parsed_text)'); |
||||
return false; |
||||
} |
||||
|
||||
// return true only if all non-admin properties of parsed_text are empty
|
||||
const is_admin_only_analysis = ['number', 'street', 'query', 'category', 'postalcode'].every((prop) => { |
||||
const is_admin_only_analysis = ['number', 'street', 'query', 'category', 'postalcode'].every((prop) => { |
||||
return _.isEmpty(request.clean.parsed_text[prop]); |
||||
}); |
||||
|
||||
debugLog.push(request, is_admin_only_analysis); |
||||
debugLog.push(request, () => ({ |
||||
reply: is_admin_only_analysis, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return is_admin_only_analysis; |
||||
}; |
||||
|
@ -1,7 +1,16 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:is_only_non_admin_layers'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
// return true IFF req.clean.layers is empty OR there are non-venue/address/street layers
|
||||
module.exports = (req, res) => ( |
||||
!_.isEmpty(_.get(req, 'clean.layers', [])) && |
||||
_.isEmpty(_.difference(req.clean.layers, ['venue', 'address', 'street'])) |
||||
); |
||||
module.exports = (req, res) => { |
||||
const is_only_non_admin_layers = !_.isEmpty(_.get(req, 'clean.layers', [])) && |
||||
_.isEmpty(_.difference(req.clean.layers, ['venue', 'address', 'street'])); |
||||
|
||||
debugLog.push(req, () => ({ |
||||
reply: is_only_non_admin_layers, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return is_only_non_admin_layers; |
||||
}; |
||||
|
@ -1,9 +1,17 @@
|
||||
const _ = require('lodash'); |
||||
const Debug = require('../../helper/debug'); |
||||
const debugLog = new Debug('controller:predicates:is_request_sources_only_whosonfirst'); |
||||
const stackTraceLine = require('../../helper/stackTraceLine'); |
||||
|
||||
// returns true IFF 'whosonfirst' is the only requested source
|
||||
module.exports = (req, res) => ( |
||||
_.isEqual( |
||||
module.exports = (req, res) => { |
||||
const is_request_sources_only_whosonfirst = _.isEqual( |
||||
_.get(req, 'clean.sources', []), |
||||
['whosonfirst'] |
||||
) |
||||
); |
||||
); |
||||
debugLog.push(req, () => ({ |
||||
reply: is_request_sources_only_whosonfirst, |
||||
stack_trace: stackTraceLine() |
||||
})); |
||||
return is_request_sources_only_whosonfirst; |
||||
}; |
||||
|
Loading…
Reference in new issue