import { Injectable } from "@angular/core" ; import { AthleteService } from "../athlete/athlete.service" ; import * as _ from "lodash" ; import { AthleteModel , AthleteSnapshotModel } from "@elevate/shared/models" ; import { AthleteSnapshotResolver } from "@elevate/shared/resolvers" ; @ Injectable ( ) export class AthleteSnapshotResolverService { public athleteSnapshotResolver : AthleteSnapshotResolver ; constructor ( public athleteService ) { } /**
     * Update or create AthleteSnapshotResolver
     */ public update ( ) { return this . athleteService . fetch ( ) . then ( ( athleteModel ) => { this . athleteSnapshotResolver = new AthleteSnapshotResolver ( athleteModel ) ; return Promise . resolve ( ) ; } ) ; } param onDate returns { AthleteSnapshotModel } public resolve ( onDate ) { if ( _ . isEmpty ( this . athleteSnapshotResolver ) ) { throw new Error ( "AthleteSnapshotResolver do not exists. Please update service at first with AthleteSnapshotResolverService#update()" ) ; } return this . athleteSnapshotResolver . resolve ( onDate ) ; } returns { AthleteSnapshotModel } public getCurrent ( ) { return this . athleteSnapshotResolver . resolve ( new Date ( ) ) ; } }