From 9b37b70812b4c7d1c35cea6c96abf71d53c53728 Mon Sep 17 00:00:00 2001 From: Jason McCollum Date: Fri, 30 Aug 2024 10:30:07 -0700 Subject: [PATCH] Parse travel mode from string to enum value --- .../frontend/src/app/core/services/csv.service.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/application/frontend/src/app/core/services/csv.service.ts b/application/frontend/src/app/core/services/csv.service.ts index a1a0daf3..797f3ec1 100644 --- a/application/frontend/src/app/core/services/csv.service.ts +++ b/application/frontend/src/app/core/services/csv.service.ts @@ -27,6 +27,7 @@ import { ILatLng, IShipment, IVehicle, + TravelMode, ValidationErrorResponse, } from '../models'; import { FileService } from './file.service'; @@ -261,7 +262,13 @@ export class CsvService { // Conditionally add each field to the vehicle object, converting from csv strings as needed const parsedVehicle = { ...this.mapKeyToModelValue('label', 'Label', vehicle, mapping), - ...this.mapKeyToModelValue('travelMode', 'TravelMode', vehicle, mapping), + ...this.mapKeyToModelValue( + 'travelMode', + 'TravelMode', + vehicle, + mapping, + this.parseTravelMode + ), ...this.mapKeyToModelValue('unloadingPolicy', 'UnloadingPolicy', vehicle, mapping), ...this.mapKeyToModelValue('startWaypoint', 'StartWaypoint', vehicle, mapping), ...this.mapKeyToModelValue('endWaypoint', 'EndWaypoint', vehicle, mapping), @@ -536,6 +543,10 @@ export class CsvService { } } + private parseTravelMode(value: string): number { + return TravelMode[value]; + } + // Check map has the provided mapKey and if the model object has a value for the converted key // Optionally run the final value through a conversiion function to transform its type private mapKeyToModelValue(