mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
implement rest of methods
This commit is contained in:
@@ -86,10 +86,6 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
||||
return entity;
|
||||
}
|
||||
|
||||
private findEntityIndexById<T extends IEntityWithId>(entityId: string, arrayToSearchIn: T[]) {
|
||||
return arrayToSearchIn.findIndex((value) => value.id === entityId);
|
||||
}
|
||||
|
||||
public async addOrUpdateSystem(system: ISystem): Promise<void> {
|
||||
const index = this.systems.findIndex((s) => s.id === system.id);
|
||||
if (index !== -1) {
|
||||
@@ -144,42 +140,49 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
||||
}
|
||||
}
|
||||
|
||||
public async removeSystemIfExists(systemId: string): Promise<ISystem | null> {
|
||||
const index = this.findEntityIndexById(systemId, this.systems);
|
||||
private async removeEntityByMatcherIfExists<T>(callback: (value: T) => boolean, arrayToSearchIn: T[]) {
|
||||
const index = arrayToSearchIn.findIndex(callback);
|
||||
if (index > -1) {
|
||||
const systemToReturn = this.systems[index];
|
||||
this.systems.splice(index, 1);
|
||||
return systemToReturn;
|
||||
const entityToReturn = arrayToSearchIn[index];
|
||||
arrayToSearchIn.splice(index, 1);
|
||||
return entityToReturn;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private async removeEntityByIdIfExists<T extends IEntityWithId>(entityId: string, arrayToSearchIn: T[]) {
|
||||
return await this.removeEntityByMatcherIfExists((value) => value.id === entityId, arrayToSearchIn);
|
||||
}
|
||||
|
||||
public async removeSystemIfExists(systemId: string): Promise<ISystem | null> {
|
||||
return await this.removeEntityByIdIfExists(systemId, this.systems);
|
||||
}
|
||||
|
||||
public async removeRouteIfExists(routeId: string): Promise<IRoute | null> {
|
||||
const index = this.findEntityIndexById(routeId, this.routes);
|
||||
if (index > -1) {
|
||||
const routeToReturn = this.routes[index];
|
||||
this.routes.splice(index, 1);
|
||||
return routeToReturn;
|
||||
}
|
||||
|
||||
return null;
|
||||
return await this.removeEntityByIdIfExists(routeId, this.routes);
|
||||
}
|
||||
|
||||
public async removeShuttleIfExists(shuttleId: string): Promise<IShuttle | null> {
|
||||
return null;
|
||||
return await this.removeEntityByIdIfExists(shuttleId, this.shuttles);
|
||||
}
|
||||
|
||||
public async removeStopIfExists(stopId: string): Promise<IStop | null> {
|
||||
return null;
|
||||
return await this.removeEntityByIdIfExists(stopId, this.stops);
|
||||
}
|
||||
|
||||
public async removeOrderedStopIfExists(stopId: string, routeId: string): Promise<IOrderedStop | null> {
|
||||
return null;
|
||||
return await this.removeEntityByMatcherIfExists((orderedStop) => {
|
||||
return orderedStop.stopId === stopId
|
||||
&& orderedStop.routeId === routeId
|
||||
}, this.orderedStops);
|
||||
}
|
||||
|
||||
public async removeEtaIfExists(shuttleId: string, stopId: string): Promise<IEta | null> {
|
||||
return null;
|
||||
return await this.removeEntityByMatcherIfExists((eta) => {
|
||||
return eta.stopId === stopId
|
||||
&& eta.shuttleId === shuttleId
|
||||
}, this.etas);
|
||||
}
|
||||
|
||||
public async clearSystemData() {
|
||||
|
||||
Reference in New Issue
Block a user