Skip to content

Commit

Permalink
fix sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyurx11 committed Nov 8, 2024
1 parent ac4a954 commit c9fb1bd
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions server/models/views/station.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,16 +412,12 @@ 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 targetStationId = direction === 'upstream' ? river.up : river.down
const targetStationType =
direction === 'upstream' ? river.up_station_type : river.down_station_type // 'M' or 'S'
const { rloi_id: currentStationId, station_type: currentStationType, qualifier, isMulti, up, down, up_station_type: upStationType, down_station_type: downStationType } = river
const currentStationQualifier = qualifier || (isMulti ? 'u' : null)
const targetStationId = direction === 'upstream' ? up : down
const targetStationType = direction === 'upstream' ? upStationType : downStationType

if (targetStationId) {
// Proceed to determine navigation link
return determineNavigationLink(
currentStationId,
currentStationType,
Expand All @@ -432,18 +428,17 @@ function createNavigationLink (river, direction) {
)
}

return getQualifierSwitchLink(currentStationType, currentStationQualifier, currentStationId, direction)
}

function getQualifierSwitchLink (currentStationType, currentStationQualifier, currentStationId, 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 direction === 'upstream' ? `${currentStationId}` : `${currentStationId}/downstream`
}

// No navigation link available
return null
}

Expand Down

0 comments on commit c9fb1bd

Please sign in to comment.