import { Injectable } from '@angular/core' ; import { AchievementHistory } from '../../../../models/achievement/achievement-history' ; import { AchievementHistoryStorageService } from '../../../achievement/achievement-history-storage.service' ; import { AchievementsLoaderService } from '../../../achievement/data/achievements-loader.service' ; @ Injectable ( ) export class AchievementUpdateHelper { constructor ( private readonly achievementHistoryStorage , private readonly achievementsLoader ) { } public async buildAchievementHistory ( ) { const [ history , achievements ] = await Promise . all ( [ this . achievementHistoryStorage . loadAll ( ) , this . achievementsLoader . getAchievements ( ) , ] ) ; return ( history . filter ( ( history ) => history . numberOfCompletions === 1 ) . map ( ( history ) => { const matchingAchievement = achievements . find ( ( ach ) => ach . id === history . achievementId ) ; if ( ! matchingAchievement ) { return null ; } return { ... history , displayName : achievements . find ( ( ach ) => ach . id === history . achievementId ) . displayName , } as AchievementHistory ; } ) . filter ( ( history ) => history ) . reverse ( ) ) ; } }