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