Advertisement
Fallonor

AwardObs

Jul 17th, 2019
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1.  
  2. //We almost never want award levels without their attending awards
  3. //It seems best to load award levels in this context
  4. private getAwardLevels(prog: Session): Observable<IncentiveTier[]> {
  5. return this.incentiveTierApi.find({
  6. where: {
  7. programId: prog.id,
  8. },
  9. include: [
  10. {
  11. relation: 'unit',
  12. },
  13. {
  14. relation: 'incentives',
  15. },
  16. {
  17. relation: 'incentiveTierIncentives',
  18. scope: {
  19. include: 'incentive',
  20. },
  21. },
  22. ],
  23. order: 'toAchieveInMi',
  24. }).do((aws: IncentiveTier[]) => console.log({AWS: aws}));
  25. }
  26.  
  27. //assume $program returns a Session object whenever it's loaded or whenever the selected value changes. Right now on my local build it's hardcoded to use my test session.
  28. private _$awardLevels: BehaviorSubject<IncentiveTier[]>;
  29. get $awardLevels(): Observable<IncentiveTier[]> {
  30. if (!this._$awardLevels) {
  31. this._$awardLevels = new BehaviorSubject<IncentiveTier[]>([]);
  32. this.$program
  33. .filter((prog: Session) => !!prog)
  34. .flatMap((prog: Session) => this.getAwardLevels(prog))
  35. .do((awds: IncentiveTier[]) => console.log({AWDS: awds}))
  36. .subscribe(this._$awardLevels);
  37. }
  38. return this._$awardLevels.asObservable();
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement