Skip to content

Commit 5e6345b

Browse files
Fix bug & refacor the first/last stop determining
Fixed last stop determining function and at the same time refactor both functions to use lodash's min and max functions. Resolves HSLdevcom/jore4##1384
1 parent f1bc38e commit 5e6345b

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

ui/src/hooks/routes/useExportRoutes.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const useExportRoutes = () => {
2929
is_used_as_timing_point: boolean;
3030
}>(jp);
3131
return (
32-
firstStop.is_used_as_timing_point && lastStop.is_used_as_timing_point
32+
firstStop?.is_used_as_timing_point && lastStop?.is_used_as_timing_point
3333
);
3434
});
3535

ui/src/utils/journeyPattern.ts

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import maxBy from 'lodash/maxBy';
2+
import minBy from 'lodash/minBy';
13
import {
24
JourneyPatternScheduledStopPointInJourneyPatternInsertInput,
35
JourneyPatternStopFragment,
@@ -103,16 +105,9 @@ type JourneyPatternWithGenericReturnType<TType> = {
103105
export const extractJourneyPatternFirstStop = <TType>(
104106
journeyPattern: JourneyPatternWithGenericReturnType<TType>,
105107
) => {
106-
return journeyPattern.scheduled_stop_point_in_journey_patterns.reduce(
107-
(minObj, currentObj) => {
108-
if (
109-
currentObj.scheduled_stop_point_sequence <
110-
minObj.scheduled_stop_point_sequence
111-
) {
112-
return currentObj;
113-
}
114-
return minObj;
115-
},
108+
return minBy(
109+
journeyPattern.scheduled_stop_point_in_journey_patterns,
110+
'scheduled_stop_point_sequence',
116111
);
117112
};
118113

@@ -122,15 +117,8 @@ export const extractJourneyPatternFirstStop = <TType>(
122117
export const extractJourneyPatternLastStop = <TType>(
123118
journeyPattern: JourneyPatternWithGenericReturnType<TType>,
124119
) => {
125-
return journeyPattern.scheduled_stop_point_in_journey_patterns.reduce(
126-
(minObj, currentObj) => {
127-
if (
128-
currentObj.scheduled_stop_point_sequence <
129-
minObj.scheduled_stop_point_sequence
130-
) {
131-
return currentObj;
132-
}
133-
return minObj;
134-
},
120+
return maxBy(
121+
journeyPattern.scheduled_stop_point_in_journey_patterns,
122+
'scheduled_stop_point_sequence',
135123
);
136124
};

0 commit comments

Comments
 (0)