mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
refactor parking structure construction into separate method
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user