mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
move index finding to separate method
This commit is contained in:
@@ -1,13 +1,5 @@
|
|||||||
import { GetterSetterRepository } from "./GetterSetterRepository";
|
import { GetterSetterRepository } from "./GetterSetterRepository";
|
||||||
import {
|
import { IEntityWithId, IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../entities/entities";
|
||||||
IEntityWithId,
|
|
||||||
IEta,
|
|
||||||
IOrderedStop,
|
|
||||||
IRoute,
|
|
||||||
IShuttle,
|
|
||||||
IStop,
|
|
||||||
ISystem
|
|
||||||
} from "../entities/entities";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An unoptimized in memory repository.
|
* An unoptimized in memory repository.
|
||||||
@@ -94,6 +86,10 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
|||||||
return entity;
|
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> {
|
public async addOrUpdateSystem(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) {
|
||||||
@@ -149,7 +145,7 @@ export class UnoptimizedInMemoryRepository implements GetterSetterRepository {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async removeSystemIfExists(systemId: string): Promise<ISystem | null> {
|
public async removeSystemIfExists(systemId: string): Promise<ISystem | null> {
|
||||||
const index = this.systems.findIndex((s) => s.id === systemId);
|
const index = this.findEntityIndexById(systemId, this.systems);
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
const systemToReturn = this.systems[index];
|
const systemToReturn = this.systems[index];
|
||||||
this.systems.splice(index, 1);
|
this.systems.splice(index, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user