All files / src/providers/init-service init-service.ts

100% Statements 14/14
100% Branches 6/6
100% Functions 7/7
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42          1x   14x   18x                                   10x 10x       8x 8x 8x 1x 7x       1x  
import { Injectable } from '@angular/core';
import { GlobalService } from '../global-service/global-service';
import { HttpClient } from '@angular/common/http';
 
@Injectable()
export class InitService {
 
    constructor ( public http: HttpClient ) {}
 
    public getInitData ( forceDevData = false ) {
        // if ( GlobalService.DEV_MODE ) {
        //     return this.getFile( GlobalService.URL_INFO_DEV );
        // }
 
        // return new Promise( ( resolve, reject ) => {
        //     return this.getFile( GlobalService.URL_INFO_PROD )
        //         .then( data => resolve( data ) )
        //         .catch( error => {
        //             return this.getFile( GlobalService.URL_INFO_DEV )
        //                 .then( data => resolve( {
        //                     content: data,
        //                     error: `Error when loading ${ GlobalService.URL_INFO_PROD }: ${error}`
        //                 } ) )
        //                 .catch( err => reject( [ error.message, err.message ] ) );
        //         } );
        // } );
 
        const url = GlobalService.DEV_MODE || forceDevData ? GlobalService.URL_INFO_DEV : GlobalService.URL_INFO_PROD;
        return this.getFile( url );
 
    }
 
    private getFile ( url ) {
        return new Promise( ( resolve, reject ) => {
            this.http.get( url ).subscribe(
                data => resolve( data ),
                error => reject( error )
            );
        } );
    }
}