refactor parking structure construction into separate method

This commit is contained in:
2025-04-11 16:11:27 -07:00
parent 6998ff529c
commit 2a01d007a9

View File

@@ -31,7 +31,18 @@ export class ChapmanTimedApiBasedParkingRepositoryLoader implements ParkingRepos
try {
if (typeof json.Structures === "object") {
const parkingStructures: IParkingStructure[] = json.Structures.map((jsonStructure: any) => {
const parkingStructures: IParkingStructure[] = json.Structures.map(this.constructIParkingStructureFromJson);
await Promise.all(parkingStructures.map(async (structure: IParkingStructure) => {
await this.repository.addOrUpdateParkingStructure(structure);
}));
}
} catch(e: any) {
throw new ApiParseError(e.message);
}
}
private constructIParkingStructureFromJson(jsonStructure: any) {
const structureToReturn: IParkingStructure = {
capacity: jsonStructure.Capacity,
coordinates: {
@@ -45,15 +56,6 @@ export class ChapmanTimedApiBasedParkingRepositoryLoader implements ParkingRepos
}
return structureToReturn;
});
await Promise.all(parkingStructures.map(async (structure: IParkingStructure) => {
this.repository.addOrUpdateParkingStructure(structure);
}));
}
} catch(e: any) {
throw new ApiParseError(e.message);
}
}
private static normalizeAddress(address: string): string {