mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
move baseUrl and supported system ids to class level
This commit is contained in:
@@ -1,10 +1,10 @@
|
|||||||
import { GetterSetterRepository } from "../repositories/GetterSetterRepository";
|
import { GetterSetterRepository } from "../repositories/GetterSetterRepository";
|
||||||
import { IEta, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
|
import { IEta, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
|
||||||
|
|
||||||
const systemIdsToSupport = ["263"];
|
|
||||||
const baseUrl = "https://passiogo.com/mapGetData.php";
|
|
||||||
|
|
||||||
export class ApiBasedRepositoryLoader {
|
export class ApiBasedRepositoryLoader {
|
||||||
|
readonly supportedSystemIds = ["263"];
|
||||||
|
readonly baseUrl = "https://passiogo.com/mapGetData.php";
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
public repository: GetterSetterRepository,
|
public repository: GetterSetterRepository,
|
||||||
) {
|
) {
|
||||||
@@ -15,12 +15,12 @@ export class ApiBasedRepositoryLoader {
|
|||||||
getSystems: "2",
|
getSystems: "2",
|
||||||
};
|
};
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${baseUrl}?${query}`);
|
const response = await fetch(`${this.baseUrl}?${query}`);
|
||||||
const json = await response.json()
|
const json = await response.json()
|
||||||
|
|
||||||
if (typeof json.all === "object") {
|
if (typeof json.all === "object") {
|
||||||
// filter down to supported systems
|
// filter down to supported systems
|
||||||
const filteredSystems = json.all.filter((jsonSystem: any) => systemIdsToSupport.includes(jsonSystem.id));
|
const filteredSystems = json.all.filter((jsonSystem: any) => this.supportedSystemIds.includes(jsonSystem.id));
|
||||||
await Promise.all(filteredSystems.map(async (system: any) => {
|
await Promise.all(filteredSystems.map(async (system: any) => {
|
||||||
const constructedSystem: ISystem = {
|
const constructedSystem: ISystem = {
|
||||||
id: system.id,
|
id: system.id,
|
||||||
@@ -47,7 +47,7 @@ export class ApiBasedRepositoryLoader {
|
|||||||
formData.set("json", JSON.stringify(formDataJsonObject));
|
formData.set("json", JSON.stringify(formDataJsonObject));
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${baseUrl}?${query}`, {
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
@@ -86,7 +86,7 @@ export class ApiBasedRepositoryLoader {
|
|||||||
formData.set("json", JSON.stringify(formDataJsonObject));
|
formData.set("json", JSON.stringify(formDataJsonObject));
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${baseUrl}?${query}`, {
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
@@ -114,7 +114,7 @@ export class ApiBasedRepositoryLoader {
|
|||||||
formData.set("json", JSON.stringify(formDataJsonObject));
|
formData.set("json", JSON.stringify(formDataJsonObject));
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${baseUrl}?${query}`, {
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
@@ -154,7 +154,7 @@ export class ApiBasedRepositoryLoader {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const query = new URLSearchParams(params).toString();
|
const query = new URLSearchParams(params).toString();
|
||||||
const response = await fetch(`${baseUrl}?${query}`, {
|
const response = await fetch(`${this.baseUrl}?${query}`, {
|
||||||
method: "GET",
|
method: "GET",
|
||||||
});
|
});
|
||||||
const json = await response.json();
|
const json = await response.json();
|
||||||
|
|||||||
Reference in New Issue
Block a user