Skip to content

Commit

Permalink
FSR-1006: Fix sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyurx11 committed Nov 8, 2024
1 parent b57e48c commit ac4a954
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions server/models/views/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,31 +414,37 @@ class ViewModel {
function createNavigationLink (river, direction) {
const currentStationId = river.rloi_id
const currentStationType = river.station_type // 'M' or 'S'
const currentStationQualifier = river.qualifier || (river.is_multi ? 'u' : null) // 'u', 'd', or null
const currentStationQualifier =
river.qualifier || (river.is_multi ? 'u' : null) // 'u', 'd', or null
const targetStationId = direction === 'upstream' ? river.up : river.down
const targetStationType = direction === 'upstream' ? river.up_station_type : river.down_station_type // 'M' or 'S'

// Handle cases where no upstream or downstream station exists
if (!targetStationId) {
if (
currentStationType === 'M' &&
((direction === 'upstream' && currentStationQualifier === 'd') ||
(direction === 'downstream' && currentStationQualifier === 'u'))
) {
// Switch between qualifiers within the same station
return direction === 'upstream' ? `${currentStationId}` : `${currentStationId}/downstream`
}
return null
const targetStationType =
direction === 'upstream' ? river.up_station_type : river.down_station_type // 'M' or 'S'

if (targetStationId) {
// Proceed to determine navigation link
return determineNavigationLink(
currentStationId,
currentStationType,
currentStationQualifier,
targetStationType,
targetStationId,
direction
)
}

if (
currentStationType === 'M' &&
((direction === 'upstream' && currentStationQualifier === 'd') ||
(direction === 'downstream' && currentStationQualifier === 'u'))
) {
// Switch between qualifiers within the same station
return direction === 'upstream'
? `${currentStationId}`
: `${currentStationId}/downstream`
}

return determineNavigationLink(
currentStationId,
currentStationType,
currentStationQualifier,
targetStationType,
targetStationId,
direction
)
// No navigation link available
return null
}

function determineNavigationLink (
Expand Down

0 comments on commit ac4a954

Please sign in to comment.