mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
update repository loader and tests to support only one system
This commit is contained in:
@@ -15,7 +15,7 @@ export class ApiResponseError extends Error {
|
||||
* which inherit from `IEntityWithId`.
|
||||
*/
|
||||
export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader {
|
||||
supportedSystemIds = ["263"];
|
||||
systemId = "263";
|
||||
baseUrl = "https://passiogo.com/mapGetData.php";
|
||||
|
||||
constructor(
|
||||
@@ -38,9 +38,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
||||
};
|
||||
const query = new URLSearchParams(params).toString();
|
||||
|
||||
const systemIds = await this.constructExistingEntityIdSet(async () => {
|
||||
return await this.repository.getSystemIfExists();
|
||||
})
|
||||
const system = await this.repository.getSystemIfExists();
|
||||
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}?${query}`);
|
||||
@@ -52,34 +50,28 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
||||
|
||||
if (typeof json.all === "object") {
|
||||
// filter down to supported systems
|
||||
const filteredSystems = json.all.filter((jsonSystem: any) => this.supportedSystemIds.includes(jsonSystem.id));
|
||||
await Promise.all(filteredSystems.map(async (system: any) => {
|
||||
const filteredSystem = json.all.find((jsonSystem: any) => jsonSystem.id === this.systemId);
|
||||
if (filteredSystem !== undefined) {
|
||||
const constructedSystem: ISystem = {
|
||||
id: system.id,
|
||||
name: system.fullname,
|
||||
id: filteredSystem.id,
|
||||
name: filteredSystem.fullname,
|
||||
};
|
||||
|
||||
await this.repository.updateSystem(constructedSystem);
|
||||
systemIds.delete(constructedSystem.id);
|
||||
}));
|
||||
}
|
||||
} else {
|
||||
throw new Error("Received JSON object does not contain `all` field")
|
||||
}
|
||||
|
||||
// Prune systems
|
||||
await Promise.all(Array.from(systemIds).map(async (systemId) => {
|
||||
await this.repository.removeSystemIfExists(systemId);
|
||||
}));
|
||||
} catch(e: any) {
|
||||
throw new ApiResponseError(e.message);
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateRouteDataForExistingSystemsInRepository() {
|
||||
const systems = await this.repository.getSystemIfExists();
|
||||
await Promise.all(systems.map(async (system) => {
|
||||
public async fetchAndUpdateRouteDataForExistingSystemInRepository() {
|
||||
const system = await this.repository.getSystemIfExists();
|
||||
if (system !== null) {
|
||||
await this.fetchAndUpdateRouteDataForSystemId(system.id);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateRouteDataForSystemId(systemId: string) {
|
||||
@@ -131,11 +123,11 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository() {
|
||||
const systems = await this.repository.getSystemIfExists();
|
||||
await Promise.all(systems.map(async (system: ISystem) => {
|
||||
public async fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemInRepository() {
|
||||
const system = await this.repository.getSystemIfExists();
|
||||
if (system !== null) {
|
||||
await this.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(system.id);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId: string) {
|
||||
@@ -177,12 +169,13 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateShuttleDataForExistingSystemsInRepository() {
|
||||
const systems = await this.repository.getSystemIfExists();
|
||||
await Promise.all(systems.map(async (system: ISystem) => {
|
||||
public async fetchAndUpdateShuttleDataForExistingSystemInRepository() {
|
||||
const system = await this.repository.getSystemIfExists();
|
||||
|
||||
if (system !== null) {
|
||||
const systemId = system.id;
|
||||
await this.fetchAndUpdateShuttleDataForSystemId(systemId);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateShuttleDataForSystemId(systemId: string) {
|
||||
@@ -243,12 +236,12 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateEtaDataForExistingStopsForSystemsInRepository() {
|
||||
const systems = await this.repository.getSystemIfExists()
|
||||
await Promise.all(systems.map(async (system: ISystem) => {
|
||||
public async fetchAndUpdateEtaDataForExistingStopsForSystemInRepository() {
|
||||
const system = await this.repository.getSystemIfExists()
|
||||
if (system !== null) {
|
||||
const systemId = system.id;
|
||||
await this.fetchAndUpdateEtaDataForExistingStopsForSystemId(systemId);
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
public async fetchAndUpdateEtaDataForExistingStopsForSystemId(systemId: string) {
|
||||
|
||||
Reference in New Issue
Block a user