Created
July 27, 2017 07:13
-
-
Save sdebaun/476d76a44fb950c402ebf0ba7af9efb3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { Observable } from 'rxjs'; | |
import { ActivatedRouteSnapshot, Resolve } from '@angular/router'; | |
import { | |
Opp, | |
OppService, | |
Project, | |
ProjectService, | |
RequestService, | |
Request, | |
UserService, | |
} from '../../sn-firebase'; | |
export type ApplyPageSources = { | |
opp$: Observable<Opp>, | |
project$: Observable<Project>, | |
request$: Observable<Request>, | |
}; | |
@Injectable() | |
export class ApplyPageSourcesResolver implements Resolve<ApplyPageSources> { | |
constructor( | |
public opps: OppService, | |
public projects: ProjectService, | |
public requests: RequestService, | |
public users: UserService, | |
) {} | |
public resolve(route: ActivatedRouteSnapshot): Observable<ApplyPageSources> { | |
const opp$ = this.opps.byKey(route.params['oppKey']); | |
const project$ = this.projects.byKey(route.params['projectKey']); | |
const request$ = this.users.uid$ | |
.switchMap(uid => this.requests.byKey(uid + route.params['oppKey'])); | |
const sources = { | |
opp$, | |
project$, | |
request$, | |
}; | |
return Observable.combineLatest(opp$, project$, request$) | |
.map(() => sources) | |
.first(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment