Skip to content

Commit

Permalink
Replace all version checking with compare-versions function
Browse files Browse the repository at this point in the history
  • Loading branch information
codemacabre committed Aug 27, 2024
1 parent fd9ee61 commit 808c78f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 4 additions & 3 deletions src/model/edges/edges.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compareVersions } from 'compare-versions';
import { curveMonotoneX } from 'd3';
import { closedRecords, latest } from '../../utils/bods';

Expand Down Expand Up @@ -58,10 +59,10 @@ export const checkInterests = (interestRelationship) => {
};

export const getOwnershipEdges = (bodsData) => {
const version = bodsData[0]?.publicationDetails?.bodsVersion || null;
const version = bodsData[0]?.publicationDetails?.bodsVersion || '0';

const filteredData = bodsData.filter((statement) => {
if (version >= Number('0.4')) {
if (compareVersions(version, '0.4') >= 0) {
return statement.recordType === 'relationship';
} else {
return statement.statementType === 'ownershipOrControlStatement';
Expand Down Expand Up @@ -94,7 +95,7 @@ export const getOwnershipEdges = (bodsData) => {
? directOrIndirect
: 'unknown';
let source, target;
if (version >= Number('0.4')) {
if (compareVersions(version, '0.4') >= 0) {
source = recordDetails.interestedParty;
target = recordDetails.subject;
} else {
Expand Down
11 changes: 6 additions & 5 deletions src/model/nodes/nodes.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { compareVersions } from 'compare-versions';
import generateNodeLabel from './nodeSVGLabel';
import { closedRecords, latest } from '../../utils/bods';
import sanitise from '../../utils/sanitiser';
Expand Down Expand Up @@ -77,10 +78,10 @@ let iconType = (nodeType) => {

// This builds up the required person object from the BODS data, using the functions above
export const getPersonNodes = (bodsData) => {
const version = bodsData[0]?.publicationDetails?.bodsVersion || null;
const version = bodsData[0]?.publicationDetails?.bodsVersion || '0';

const filteredData = bodsData.filter((statement) => {
if (version >= Number('0.4')) {
if (compareVersions(version, '0.4') >= 0) {
return statement.recordType === 'person';
} else {
return statement.statementType === 'personStatement';
Expand Down Expand Up @@ -127,10 +128,10 @@ export const getPersonNodes = (bodsData) => {

// This builds up the required entity object from the BODS data, using the functions above
export const getEntityNodes = (bodsData) => {
const version = bodsData[0]?.publicationDetails?.bodsVersion || null;
const version = bodsData[0]?.publicationDetails?.bodsVersion || '0';

const filteredData = bodsData.filter((statement) => {
if (version >= Number('0.4')) {
if (compareVersions(version, '0.4') >= 0) {
return statement.recordType === 'entity';
} else {
return statement.statementType === 'entityStatement';
Expand All @@ -153,7 +154,7 @@ export const getEntityNodes = (bodsData) => {

let countryCode;

if (version >= Number('0.4')) {
if (compareVersions(version, '0.4') >= 0) {
countryCode = recordDetails.jurisdiction ? sanitise(recordDetails.jurisdiction.code) : null;
} else {
// This gets the country code from v0.2 BODS (incorporatedInJurisdiction)
Expand Down
3 changes: 2 additions & 1 deletion src/utils/bods.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { compareVersions } from 'compare-versions';
export const closedRecords = new Set();

export const latest = (statements, closedRecords, version) => {
if (version >= Number('0.4')) {
if (compareVersions(version, '0.4') >= 0) {
const statementMap = {};

statements.forEach((statement) => {
Expand Down

0 comments on commit 808c78f

Please sign in to comment.