From c9fb1bd0de51ef5c1efb038822aa749a212b8c1d Mon Sep 17 00:00:00 2001 From: keyurx11 Date: Fri, 8 Nov 2024 11:27:58 +0000 Subject: [PATCH] fix sonar --- server/models/views/station.js | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/server/models/views/station.js b/server/models/views/station.js index 06e0cf0c3..f08840474 100644 --- a/server/models/views/station.js +++ b/server/models/views/station.js @@ -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, @@ -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 }