diff --git a/controller/search.js b/controller/search.js index 8af6bec4..7e17b0bd 100644 --- a/controller/search.js +++ b/controller/search.js @@ -1,4 +1,3 @@ - var service = { search: require('../service/search') }; function setup( backend, query ){ diff --git a/helper/layers.js b/helper/layers.js index aa625a6e..a5a57d7f 100644 --- a/helper/layers.js +++ b/helper/layers.js @@ -1,6 +1,6 @@ module.exports = function(alias_layers) { // make a copy of the array so, you are not modifying original ref - var layers = alias_layers.slice(0); + var layers = alias_layers.slice(0); // expand aliases var expand_aliases = function(alias, layers, layer_indeces) { diff --git a/helper/query_parser.js b/helper/query_parser.js index 88729c86..7c5ba4b0 100644 --- a/helper/query_parser.js +++ b/helper/query_parser.js @@ -5,7 +5,7 @@ var get_layers = require('../helper/layers'); var delim = ','; module.exports = function(query) { - + var tokenized = query.split(/[ ,]+/); var hasNumber = /\d/.test(query); @@ -17,11 +17,11 @@ module.exports = function(query) { if ( delimIndex !== -1 ) { address.name = query.substring(0, delimIndex); address.admin_parts = query.substring(delimIndex + 1).trim(); - } + } return address; }; - + var getTargetLayersWhenAddressParsingIsNotNecessary = function(query) { var address = {}; // set target_layer if input length <= 3 characters @@ -32,7 +32,7 @@ module.exports = function(query) { // no need to hit address layers if there's only one (or two) token(s) address.target_layer = get_layers(['admin', 'poi']); } - + return address.target_layer ? address : null; }; @@ -49,10 +49,10 @@ module.exports = function(query) { var addressWithAdminParts = getAdminPartsBySplittingOnDelim(query); var addressWithTargetLayers= getTargetLayersWhenAddressParsingIsNotNecessary(query); - var addressWithAddressParts= !addressWithTargetLayers ? getAddressParts(query) : {}; + var addressWithAddressParts= !addressWithTargetLayers ? getAddressParts(query) : {}; - var parsedAddress = extend(addressWithAdminParts, - addressWithTargetLayers, + var parsedAddress = extend(addressWithAdminParts, + addressWithTargetLayers, addressWithAddressParts); var address_parts = [ 'name', @@ -69,7 +69,7 @@ module.exports = function(query) { var parsed_input = {}; - address_parts.forEach(function(part){ + address_parts.forEach(function(part){ if (parsedAddress[part]) { parsed_input[part] = parsedAddress[part]; } @@ -90,4 +90,4 @@ module.exports = function(query) { // regions: parsedAddress.regions, // admin_parts: parsedAddress.admin_parts, // target_layer: parsedAddress.target_layer -// } \ No newline at end of file +// } diff --git a/sanitiser/_id.js b/sanitiser/_id.js index ac2432e6..a8424363 100644 --- a/sanitiser/_id.js +++ b/sanitiser/_id.js @@ -5,7 +5,6 @@ var isObject = require('is-object'); // so, both type and id are required fields. function sanitize( req ){ - req.clean = req.clean || {}; var params = req.query; var indeces = require('../query/indeces'); @@ -30,7 +29,7 @@ function sanitize( req ){ if( params && params.id && params.id.length ){ req.clean.ids = []; params.ids = Array.isArray(params.id) ? params.id : [params.id]; - + // de-dupe params.ids = params.ids.filter(function(item, pos) { return params.ids.indexOf(item) === pos; @@ -38,7 +37,7 @@ function sanitize( req ){ for (var i=0; i0' }; } - + req.clean.input = params.input; req.clean.parsed_input = query_parse(params.input); - return { 'error': false }; - } // export function -module.exports = sanitize; \ No newline at end of file +module.exports = sanitize; diff --git a/sanitiser/_layers.js b/sanitiser/_layers.js index fa44336e..2ad5c42f 100644 --- a/sanitiser/_layers.js +++ b/sanitiser/_layers.js @@ -5,7 +5,6 @@ var isObject = require('is-object'), // validate inputs, convert types and apply defaults function sanitize( req ){ - var clean = req.clean || {}; var params= req.query; @@ -42,7 +41,7 @@ function sanitize( req ){ // pass validated params to next middleware clean.layers = get_layers(layers); req.clean = clean; - + return { 'error': false }; } diff --git a/test/unit/helper/query_parser.js b/test/unit/helper/query_parser.js index bf10b154..c82a31a2 100644 --- a/test/unit/helper/query_parser.js +++ b/test/unit/helper/query_parser.js @@ -67,13 +67,13 @@ module.exports.tests.parse_one_or_more_tokens = function(test, common) { var target_layer = get_layers(['admin', 'poi']); t.equal(typeof address, 'object', 'valid object'); - + if (parse_address) { t.deepEqual(address.regions.join(''), query, 'since query contained a number, it went through address parsing'); } else { - t.deepEqual(address.target_layer, target_layer, 'admin_parts set correctly to ' + target_layer.join(', ')); + t.deepEqual(address.target_layer, target_layer, 'admin_parts set correctly to ' + target_layer.join(', ')); } - + t.end(); }); }; @@ -88,32 +88,32 @@ module.exports.tests.parse_one_or_more_tokens = function(test, common) { }; module.exports.tests.parse_address = function(test, common) { - var addresses_nonum = [{ non_street: 'main particle', city: 'new york'}, - { non_street: 'biggg city block' }, + var addresses_nonum = [{ non_street: 'main particle', city: 'new york'}, + { non_street: 'biggg city block' }, { non_street: 'the empire state building' } ]; - var address_with_num = [{ number: 123, street: 'main st', city: 'new york', state: 'ny'}, - { number: 456, street: 'pine ave', city: 'san francisco', state: 'CA'}, + var address_with_num = [{ number: 123, street: 'main st', city: 'new york', state: 'ny'}, + { number: 456, street: 'pine ave', city: 'san francisco', state: 'CA'}, { number: 1980, street: 'house st', city: 'hoboken', state: 'NY'} ]; - var address_with_zip = [{ number: 1, street: 'main st', city: 'new york', state: 'ny', zip: 10010}, - { number: 4, street: 'ape ave', city: 'san diego', state: 'CA', zip: 98970}, + var address_with_zip = [{ number: 1, street: 'main st', city: 'new york', state: 'ny', zip: 10010}, + { number: 4, street: 'ape ave', city: 'san diego', state: 'CA', zip: 98970}, { number: 19, street: 'house dr', city: 'houston', state: 'TX', zip: 79089} ]; var testParse = function(query, hasNumber, hasZip) { - var testcase = 'parse query with ' + (hasNumber ? 'a house number ': 'no house number '); + var testcase = 'parse query with ' + (hasNumber ? 'a house number ': 'no house number '); testcase += 'and ' + (hasZip ? 'a zip ' : 'no zip '); test(testcase, function(t) { var query_string = ''; - for (var k in query) { + for (var k in query) { query_string += ' ' + query[k]; } // remove leading whitespace query_string = query_string.substring(1); - + var address = parser(query_string); var non_address_layer = get_layers(['admin', 'poi']); @@ -126,14 +126,14 @@ module.exports.tests.parse_address = function(test, common) { } if ((hasNumber || hasZip) && query.street) { - t.equal(typeof address.number, 'number', 'valid house number format (' + address.number + ')'); + t.equal(typeof address.number, 'number', 'valid house number format (' + address.number + ')'); t.equal(address.number, query.number, 'correct house number (' + query.number + ')'); - t.equal(typeof address.street, 'string', 'valid street name format (' + address.street + ')'); + t.equal(typeof address.street, 'string', 'valid street name format (' + address.street + ')'); t.equal(address.street, query.street, 'correct street name (' + query.street + ')'); } - + if (hasZip) { - t.equal(typeof address.postalcode, 'number', 'valid zip (' + address.postalcode + ')'); + t.equal(typeof address.postalcode, 'number', 'valid zip (' + address.postalcode + ')'); t.equal(address.postalcode, query.zip, 'correct postal code (' + query.zip + ')'); }