mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
rename update method and update return types
This commit is contained in:
@@ -59,7 +59,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
|||||||
name: system.fullname,
|
name: system.fullname,
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.repository.addOrUpdateSystem(constructedSystem);
|
await this.repository.updateSystem(constructedSystem);
|
||||||
systemIds.delete(constructedSystem.id);
|
systemIds.delete(constructedSystem.id);
|
||||||
}));
|
}));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -4456,7 +4456,7 @@ const etas: IEta[] = [
|
|||||||
|
|
||||||
export async function loadShuttleTestData(repository: ShuttleGetterSetterRepository) {
|
export async function loadShuttleTestData(repository: ShuttleGetterSetterRepository) {
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await repository.addOrUpdateSystem(system);
|
await repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
await Promise.all(routes.map(async (route) => {
|
await Promise.all(routes.map(async (route) => {
|
||||||
await repository.addOrUpdateRoute(route);
|
await repository.addOrUpdateRoute(route);
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
|
import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
|
||||||
|
|
||||||
export interface ShuttleGetterRepository {
|
export interface ShuttleGetterRepository {
|
||||||
getSystemIfExists(): Promise<ISystem[]>;
|
getSystemIfExists(): Promise<ISystem | null>;
|
||||||
getSystemById(systemId: string): Promise<ISystem | null>;
|
|
||||||
|
|
||||||
getStopsBySystemId(systemId: string): Promise<IStop[]>;
|
getStopsBySystemId(systemId: string): Promise<IStop[]>;
|
||||||
getStopById(stopId: string): Promise<IStop | null>;
|
getStopById(stopId: string): Promise<IStop | null>;
|
||||||
|
|||||||
@@ -12,14 +12,13 @@ import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entitie
|
|||||||
*/
|
*/
|
||||||
export interface ShuttleGetterSetterRepository extends ShuttleGetterRepository {
|
export interface ShuttleGetterSetterRepository extends ShuttleGetterRepository {
|
||||||
// Setter methods
|
// Setter methods
|
||||||
addOrUpdateSystem(system: ISystem): Promise<void>;
|
updateSystem(system: ISystem): Promise<void>;
|
||||||
addOrUpdateRoute(route: IRoute): Promise<void>;
|
addOrUpdateRoute(route: IRoute): Promise<void>;
|
||||||
addOrUpdateShuttle(shuttle: IShuttle): Promise<void>;
|
addOrUpdateShuttle(shuttle: IShuttle): Promise<void>;
|
||||||
addOrUpdateStop(stop: IStop): Promise<void>;
|
addOrUpdateStop(stop: IStop): Promise<void>;
|
||||||
addOrUpdateOrderedStop(orderedStop: IOrderedStop): Promise<void>;
|
addOrUpdateOrderedStop(orderedStop: IOrderedStop): Promise<void>;
|
||||||
addOrUpdateEta(eta: IEta): Promise<void>;
|
addOrUpdateEta(eta: IEta): Promise<void>;
|
||||||
|
|
||||||
removeSystemIfExists(systemId: string): Promise<ISystem | null>;
|
|
||||||
removeRouteIfExists(routeId: string): Promise<IRoute | null>;
|
removeRouteIfExists(routeId: string): Promise<IRoute | null>;
|
||||||
removeShuttleIfExists(shuttleId: string): Promise<IShuttle | null>;
|
removeShuttleIfExists(shuttleId: string): Promise<IShuttle | null>;
|
||||||
removeStopIfExists(stopId: string): Promise<IStop | null>;
|
removeStopIfExists(stopId: string): Promise<IStop | null>;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { IEntityWithId, IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } f
|
|||||||
* switching to another data store later anyways)
|
* switching to another data store later anyways)
|
||||||
*/
|
*/
|
||||||
export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetterRepository {
|
export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetterRepository {
|
||||||
private systems: ISystem[] = [];
|
private system: ISystem | null = null;
|
||||||
private stops: IStop[] = [];
|
private stops: IStop[] = [];
|
||||||
private routes: IRoute[] = [];
|
private routes: IRoute[] = [];
|
||||||
private shuttles: IShuttle[] = [];
|
private shuttles: IShuttle[] = [];
|
||||||
@@ -17,7 +17,7 @@ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetter
|
|||||||
private subscribers: ((eta: IEta) => void)[] = [];
|
private subscribers: ((eta: IEta) => void)[] = [];
|
||||||
|
|
||||||
public async getSystemIfExists() {
|
public async getSystemIfExists() {
|
||||||
return this.systems;
|
return this.system;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getSystemById(systemId: string) {
|
public async getSystemById(systemId: string) {
|
||||||
@@ -99,7 +99,7 @@ export class UnoptimizedInMemoryShuttleRepository implements ShuttleGetterSetter
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async addOrUpdateSystem(system: ISystem): Promise<void> {
|
public async updateSystem(system: ISystem): Promise<void> {
|
||||||
const index = this.systems.findIndex((s) => s.id === system.id);
|
const index = this.systems.findIndex((s) => s.id === system.id);
|
||||||
if (index !== -1) {
|
if (index !== -1) {
|
||||||
this.systems[index] = system; // Update existing
|
this.systems[index] = system; // Update existing
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
// Arrange
|
// Arrange
|
||||||
const systemsToPrune = generateMockSystems();
|
const systemsToPrune = generateMockSystems();
|
||||||
await Promise.all(systemsToPrune.map(async (system) => {
|
await Promise.all(systemsToPrune.map(async (system) => {
|
||||||
await loader.repository.addOrUpdateSystem(system);
|
await loader.repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const numberOfSystemsInResponse = fetchSystemDataSuccessfulResponse.all.length;
|
const numberOfSystemsInResponse = fetchSystemDataSuccessfulResponse.all.length;
|
||||||
@@ -78,7 +78,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
const systems = generateMockSystems();
|
const systems = generateMockSystems();
|
||||||
|
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await loader.repository.addOrUpdateSystem(system);
|
await loader.repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await loader.fetchAndUpdateRouteDataForExistingSystemsInRepository();
|
await loader.fetchAndUpdateRouteDataForExistingSystemsInRepository();
|
||||||
@@ -128,7 +128,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
const systems = generateMockSystems();
|
const systems = generateMockSystems();
|
||||||
|
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await loader.repository.addOrUpdateSystem(system);
|
await loader.repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository();
|
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository();
|
||||||
@@ -183,7 +183,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
|
|
||||||
const systems = generateMockSystems();
|
const systems = generateMockSystems();
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await loader.repository.addOrUpdateSystem(system);
|
await loader.repository.updateSystem(system);
|
||||||
}))
|
}))
|
||||||
|
|
||||||
await loader.fetchAndUpdateShuttleDataForExistingSystemsInRepository();
|
await loader.fetchAndUpdateShuttleDataForExistingSystemsInRepository();
|
||||||
@@ -226,7 +226,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
|
|
||||||
const systems = generateMockSystems();
|
const systems = generateMockSystems();
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await loader.repository.addOrUpdateSystem(system);
|
await loader.repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await loader.fetchAndUpdateEtaDataForExistingStopsForSystemsInRepository();
|
await loader.fetchAndUpdateEtaDataForExistingStopsForSystemsInRepository();
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
describe("getSystems", () => {
|
describe("getSystems", () => {
|
||||||
test("gets the system stored in the repository", async () => {
|
test("gets the system stored in the repository", async () => {
|
||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
await repository.addOrUpdateSystem(mockSystems[0]);
|
await repository.updateSystem(mockSystems[0]);
|
||||||
|
|
||||||
const result = await repository.getSystemIfExists();
|
const result = await repository.getSystemIfExists();
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
test("gets a system by the ID if it exists", async () => {
|
test("gets a system by the ID if it exists", async () => {
|
||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
for (const system of mockSystems) {
|
for (const system of mockSystems) {
|
||||||
await repository.addOrUpdateSystem(system);
|
await repository.updateSystem(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await repository.getSystemById("2");
|
const result = await repository.getSystemById("2");
|
||||||
@@ -327,7 +327,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
const newSystem = mockSystems[0];
|
const newSystem = mockSystems[0];
|
||||||
|
|
||||||
await repository.addOrUpdateSystem(newSystem);
|
await repository.updateSystem(newSystem);
|
||||||
|
|
||||||
const result = await repository.getSystemIfExists();
|
const result = await repository.getSystemIfExists();
|
||||||
expect(result).toEqual([newSystem]);
|
expect(result).toEqual([newSystem]);
|
||||||
@@ -339,8 +339,8 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
const updatedSystem = structuredClone(existingSystem);
|
const updatedSystem = structuredClone(existingSystem);
|
||||||
updatedSystem.name = "Updated System";
|
updatedSystem.name = "Updated System";
|
||||||
|
|
||||||
await repository.addOrUpdateSystem(existingSystem);
|
await repository.updateSystem(existingSystem);
|
||||||
await repository.addOrUpdateSystem(updatedSystem);
|
await repository.updateSystem(updatedSystem);
|
||||||
|
|
||||||
const result = await repository.getSystemIfExists();
|
const result = await repository.getSystemIfExists();
|
||||||
expect(result).toEqual([updatedSystem]);
|
expect(result).toEqual([updatedSystem]);
|
||||||
@@ -476,7 +476,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
test("removes system given ID", async () => {
|
test("removes system given ID", async () => {
|
||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
await Promise.all(mockSystems.map(async (system) => {
|
await Promise.all(mockSystems.map(async (system) => {
|
||||||
await repository.addOrUpdateSystem(system);
|
await repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const systemToRemove = mockSystems[0];
|
const systemToRemove = mockSystems[0];
|
||||||
@@ -489,7 +489,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
test("does nothing if system doesn't exist", async () => {
|
test("does nothing if system doesn't exist", async () => {
|
||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
await Promise.all(mockSystems.map(async (system) => {
|
await Promise.all(mockSystems.map(async (system) => {
|
||||||
await repository.addOrUpdateSystem(system);
|
await repository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await repository.removeSystemIfExists("nonexistent-id");
|
await repository.removeSystemIfExists("nonexistent-id");
|
||||||
@@ -664,7 +664,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
test("clears all systems from the repository", async () => {
|
test("clears all systems from the repository", async () => {
|
||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
for (const system of mockSystems) {
|
for (const system of mockSystems) {
|
||||||
await repository.addOrUpdateSystem(system);
|
await repository.updateSystem(system);
|
||||||
}
|
}
|
||||||
|
|
||||||
await repository.clearSystemData();
|
await repository.clearSystemData();
|
||||||
@@ -676,7 +676,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
test("clears system data when the repository has data", async () => {
|
test("clears system data when the repository has data", async () => {
|
||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
const system = mockSystems[0];
|
const system = mockSystems[0];
|
||||||
await repository.addOrUpdateSystem(system);
|
await repository.updateSystem(system);
|
||||||
|
|
||||||
await repository.clearSystemData();
|
await repository.clearSystemData();
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ describe("QueryResolvers", () => {
|
|||||||
async function addMockSystems() {
|
async function addMockSystems() {
|
||||||
const systems = generateMockSystems();
|
const systems = generateMockSystems();
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await context.shuttleRepository.addOrUpdateSystem(system);
|
await context.shuttleRepository.updateSystem(system);
|
||||||
}));
|
}));
|
||||||
return systems;
|
return systems;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ describe("SystemResolvers", () => {
|
|||||||
...mockSystem,
|
...mockSystem,
|
||||||
id: "2",
|
id: "2",
|
||||||
}
|
}
|
||||||
await context.shuttleRepository.addOrUpdateSystem(updatedSystem);
|
await context.shuttleRepository.updateSystem(updatedSystem);
|
||||||
|
|
||||||
const mockStop = await addMockStopToRepository(context.shuttleRepository, updatedSystem.id);
|
const mockStop = await addMockStopToRepository(context.shuttleRepository, updatedSystem.id);
|
||||||
|
|
||||||
@@ -199,7 +199,7 @@ describe("SystemResolvers", () => {
|
|||||||
...mockSystem,
|
...mockSystem,
|
||||||
id: "2",
|
id: "2",
|
||||||
}
|
}
|
||||||
await context.shuttleRepository.addOrUpdateSystem(updatedSystem);
|
await context.shuttleRepository.updateSystem(updatedSystem);
|
||||||
|
|
||||||
const mockRoute = await addMockRouteToRepository(context.shuttleRepository, updatedSystem.id);
|
const mockRoute = await addMockRouteToRepository(context.shuttleRepository, updatedSystem.id);
|
||||||
|
|
||||||
@@ -265,7 +265,7 @@ describe("SystemResolvers", () => {
|
|||||||
...mockSystem,
|
...mockSystem,
|
||||||
id: "2",
|
id: "2",
|
||||||
}
|
}
|
||||||
await context.shuttleRepository.addOrUpdateSystem(updatedSystem);
|
await context.shuttleRepository.updateSystem(updatedSystem);
|
||||||
|
|
||||||
const mockShuttle = await addMockShuttleToRepository(context.shuttleRepository, updatedSystem.id);
|
const mockShuttle = await addMockShuttleToRepository(context.shuttleRepository, updatedSystem.id);
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ export async function addMockSystemToRepository(repository: ShuttleGetterSetterR
|
|||||||
const mockSystems = generateMockSystems();
|
const mockSystems = generateMockSystems();
|
||||||
const mockSystem = mockSystems[0];
|
const mockSystem = mockSystems[0];
|
||||||
mockSystem.id = "1";
|
mockSystem.id = "1";
|
||||||
await repository.addOrUpdateSystem(mockSystem);
|
await repository.updateSystem(mockSystem);
|
||||||
|
|
||||||
return mockSystem;
|
return mockSystem;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user