Skip to content

Commit

Permalink
Parse travel mode from string to enum value
Browse files Browse the repository at this point in the history
  • Loading branch information
jmccollum-woolpert committed Aug 30, 2024
1 parent 2b988c1 commit 9b37b70
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion application/frontend/src/app/core/services/csv.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
ILatLng,
IShipment,
IVehicle,
TravelMode,
ValidationErrorResponse,
} from '../models';
import { FileService } from './file.service';
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 9b37b70

Please sign in to comment.