| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Injectable, Type } from '@angular/core'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { Logger } from './logger.service'; | 
					
						
							|  |  |  | import { Hero } from './hero'; | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-17 13:49:33 -08:00
										 |  |  | const HEROES = [ | 
					
						
							|  |  |  |         new Hero('Windstorm', 'Weather mastery'), | 
					
						
							|  |  |  |         new Hero('Mr. Nice', 'Killing them with kindness'), | 
					
						
							|  |  |  |         new Hero('Magneta', 'Manipulates metalic objects') | 
					
						
							|  |  |  |       ]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  | @Injectable() | 
					
						
							|  |  |  | export class BackendService { | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |   constructor(private logger: Logger) {} | 
					
						
							| 
									
										
										
										
											2015-12-11 15:37:35 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-01 02:08:57 +01:00
										 |  |  |   getAll(type: Type<any>): PromiseLike<any[]> { | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  |     if (type === Hero) { | 
					
						
							| 
									
										
										
										
											2015-12-17 13:49:33 -08:00
										 |  |  |       // TODO get from the database
 | 
					
						
							|  |  |  |       return Promise.resolve<Hero[]>(HEROES); | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  |     } | 
					
						
							|  |  |  |     let err = new Error('Cannot get object of this type'); | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     this.logger.error(err); | 
					
						
							| 
									
										
										
										
											2015-11-28 20:43:09 -08:00
										 |  |  |     throw err; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | } |