Skip to content

Commit

Permalink
fix: issue fixed and two other methods refactored to same code struct…
Browse files Browse the repository at this point in the history
…ure as the getTrainrunFrequency method (#383)
  • Loading branch information
aiAdrian authored Dec 12, 2024
1 parent c6ea6fe commit e864528
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/app/services/data/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,27 +211,33 @@ export class DataService implements OnDestroy {
}

getTrainrunCategory(categoryId: number): TrainrunCategory {
return this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunCategories.find(
const found = this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunCategories.find(
(trainrunCategory) => trainrunCategory.id === categoryId,
);
if (found === undefined) {
return this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunCategories.find((freq) => true);
}
return found;
}

getTrainrunFrequency(frequencyId: number): TrainrunFrequency {
if (frequencyId > 5) {
frequencyId = 5; // ensure no overflow happens (HVZ, zeitweise -> remove)
}
return this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunFrequencies.find(
const found = this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunFrequencies.find(
(trainrunFrequency) => trainrunFrequency.id === frequencyId,
);
if (found === undefined) {
return this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunFrequencies.find((freq) => true);
}
return found;
}

getTrainrunTimeCategory(timeCategoryId: number): TrainrunTimeCategory {
if (timeCategoryId === undefined) {
timeCategoryId = 0; // set to default
}
return this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunTimeCategories.find(
const found = this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunTimeCategories.find(
(trainrunTimeCategory) => trainrunTimeCategory.id === timeCategoryId,
);
if (found === undefined) {
return this.netzgrafikDtoStore.netzgrafikDto.metadata.trainrunTimeCategories.find((freq) => true);
}
return found;
}

getTrainrunCategories(): TrainrunCategory[] {
Expand Down

0 comments on commit e864528

Please sign in to comment.