Browse Source

Switching unit attribute to always be last also for standard and changed concatination to be a bit cleaner using array.join

pull/1052/head
sweco-semhul 7 years ago
parent
commit
6b8c9f6bbf
  1. 14
      middleware/localNamingConventions.js
  2. 2
      test/unit/middleware/localNamingConventions.js

14
middleware/localNamingConventions.js

@ -45,12 +45,18 @@ function applyLocalNamingConventions(req, res, next) {
// flip the housenumber and street name // flip the housenumber and street name
// eg. '101 Grolmanstraße' -> 'Grolmanstraße 101' // eg. '101 Grolmanstraße' -> 'Grolmanstraße 101'
function flipNumberAndStreet(place) { function flipNumberAndStreet(place) {
var unit = ''; var standard = ( [ place.address_parts.number, place.address_parts.street ] ),
flipped = ( [ place.address_parts.street, place.address_parts.number ] );
// unit attribte added if set
if(place.address_parts.hasOwnProperty('unit')) { if(place.address_parts.hasOwnProperty('unit')) {
unit = ' ' + place.address_parts.unit; standard.push(place.address_parts.unit);
flipped.push(place.address_parts.unit);
} }
var standard = ( place.address_parts.number + unit + ' ' + place.address_parts.street ),
flipped = ( place.address_parts.street + ' ' + place.address_parts.number + unit ); // join into strings
standard = standard.join(' ');
flipped = flipped.join(' ');
// flip street name and housenumber // flip street name and housenumber
if( place.name.default === standard ){ if( place.name.default === standard ){

2
test/unit/middleware/localNamingConventions.js

@ -93,7 +93,7 @@ module.exports.tests.flipNumberAndStreet = function(test, common) {
var dkAddressWithUnit = { var dkAddressWithUnit = {
'_id': 'test5', '_id': 'test5',
'_type': 'test', '_type': 'test',
'name': { 'default': '26 2 th Nikolaj Plads' }, 'name': { 'default': '26 Nikolaj Plads 2 th' },
'center_point': { 'lon': 12.580921, 'lat': 55.678665 }, 'center_point': { 'lon': 12.580921, 'lat': 55.678665 },
'address_parts': { 'address_parts': {
'zip': '1067', 'zip': '1067',

Loading…
Cancel
Save