Skip to content

Commit

Permalink
fixup! front: add new stdcm error when origin and destination are the…
Browse files Browse the repository at this point in the history
… same
  • Loading branch information
Sh099078 committed Jan 14, 2025
1 parent 94aee2d commit df926d1
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 14 deletions.
2 changes: 1 addition & 1 deletion front/public/locales/en/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"noScheduledPoint": "The calculation requires either the origin or destination schedule.",
"pathfindingFailed": "No path have been found for these waypoints.",
"requestFailed": "Calculation error for last minute train path",
"sameOriginAndDestination": "The origin and destination must be different."
"zeroLengthPath": "The path cannot have a null length."
},
"stdcmResults": "Results",
"stdcmSimulationReport": "Path simulation report",
Expand Down
2 changes: 1 addition & 1 deletion front/public/locales/fr/stdcm.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
"noScheduledPoint": "Le calcul a besoin de l'horaire d'origine ou de celui de la destination.",
"pathfindingFailed": "Aucun chemin n'a été trouvé pour ces points de jalonnement.",
"requestFailed": "Erreur de calcul Sillon de dernière minute",
"sameOriginAndDestination": "L'origine et la destination doivent être différentes."
"zeroLengthPath": "Le chemin ne peut pas avoir de longueur nulle."
},
"stdcmResults": "Résultats",
"stdcmSimulationReport": "Fiche simulation",
Expand Down
2 changes: 1 addition & 1 deletion front/src/applications/stdcm/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ export enum StdcmConfigErrorTypes {
PATHFINDING_FAILED = 'pathfindingFailed',
BOTH_POINT_SCHEDULED = 'bothPointAreScheduled',
NO_SCHEDULED_POINT = 'noScheduledPoint',
SAME_ORIGIN_AND_DESTINATION = 'sameOriginAndDestination',
ZERO_LENGTH_PATH = 'zeroLengthPath',
}

export type StdcmConfigErrors = {
Expand Down
18 changes: 7 additions & 11 deletions front/src/applications/stdcm/utils/checkStdcmConfigErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,20 @@ const checkStdcmConfigErrors = (
throw new Error('Last step can not be a via');
}

if (
origin.location!.uic === destination.location!.uic &&
origin.location!.secondary_code === destination.location!.secondary_code
) {
return { errorType: StdcmConfigErrorTypes.ZERO_LENGTH_PATH };
}

if (pathfindingStateError) {
return { errorType: StdcmConfigErrorTypes.PATHFINDING_FAILED };
}

const isOriginRespectDestinationSchedule =
origin.arrivalType === ArrivalTimeTypes.RESPECT_DESTINATION_SCHEDULE;

if (
'uic' in origin &&
'uic' in destination &&
'ch' in origin &&
'ch' in destination &&
origin.uic === destination.uic &&
origin.ch === destination.ch
) {
return { errorType: StdcmConfigErrorTypes.SAME_ORIGIN_AND_DESTINATION };
}

const isDestinationASAP = destination.arrivalType === ArrivalTimeTypes.ASAP;

const areBothPointsNotSchedule = isOriginRespectDestinationSchedule && isDestinationASAP;
Expand Down

0 comments on commit df926d1

Please sign in to comment.