Skip to content

Commit

Permalink
Simplify logic
Browse files Browse the repository at this point in the history
  • Loading branch information
orangejulius committed Mar 7, 2022
1 parent cebaf80 commit 533884c
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions helper/diffPlaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,29 +188,28 @@ function isAddressDifferent(item1, item2){
}

function isGeonamesConcordanceSame(item1, item2) {
let wof_record;
let gn_record;

if (item1.source === 'geonames' && item2.source === 'whosonfirst') {
gn_record = item1;
wof_record = item2;
} else if (item2.source === 'geonames' && item1.source === 'whosonfirst') {
gn_record = item2;
wof_record = item1;
} else {
// could not match to one geonames and one wof concordance, so this check does not apply
const items = [item1, item2];

const wof_record = items.find(i => i.source === 'whosonfirst');
const gn_record = items.find(i => i.source === 'geonames');

// must have found one wof and one gn record or this check does not apply
if (!wof_record || !gn_record) { return false; }

const concordances = _.get(wof_record, 'addendum.concordances');

if (!concordances) {
return false;
}

const concordances = _.get(wof_record, 'addendum.concordances');
const json = codec.decode(concordances);
const concordance_id = json['gn:id'];

if (concordances) {
const json = codec.decode(concordances);
const concordance_id = json['gn:id'];
if (!concordance_id || !_.isNumber(concordance_id)) { return false; }

if (concordance_id && typeof concordance_id === 'number' && concordance_id.toString() === gn_record.source_id) {
return true;
}
// only records with a matching concordance pass this check
if (concordance_id.toString() === gn_record.source_id) {
return true;
}

return false;
Expand Down

0 comments on commit 533884c

Please sign in to comment.