| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Injectable } from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { Hero }       from './hero'; | 
					
						
							|  |  |  | import { HEROES }     from './mock-heroes'; | 
					
						
							|  |  |  | import { Logger }     from '../logger.service'; | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Injectable() | 
					
						
							|  |  |  | export class HeroService { | 
					
						
							|  |  |  |   private _user:string; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // #docregion internals
 | 
					
						
							|  |  |  |   constructor( | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     private logger: Logger, | 
					
						
							|  |  |  |     private isAuthorized: boolean) { } | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   getHeroes() { | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     let auth = this.isAuthorized ? 'authorized ': 'unauthorized'; | 
					
						
							|  |  |  |     this.logger.log(`Getting heroes for ${auth} user.`); | 
					
						
							|  |  |  |     return HEROES.filter(hero => this.isAuthorized || !hero.isSecret); | 
					
						
							| 
									
										
										
										
											2016-01-11 13:49:12 +01:00
										 |  |  |   } | 
					
						
							|  |  |  |   // #enddocregion internals
 | 
					
						
							|  |  |  | } |