import { Injectable } from '@angular/core' ; import { Observable } from "rxjs/Observable" ; import { Account , Ticket } from "../store/models" ; import { Http , } from "@angular/http" ; import { BaseService } from "./base.service" ; import { Store } from "@ngrx/store" ; import { State } from "../store" ; import { PlanetaKinoV2Service } from "./planetakino-api/planetakino-api.service" ; import { ServiceResponse } from './service-response.model' ; import { PlanetaKinoV2JsonResponse } from "./planetakino-api/json-response" ; import { Mapper } from './mapper' ; @ Injectable ( ) export class AccountService extends BaseService { constructor ( http , private planetaKinoService , private store ) { super ( http ) ; } login ( login , password ) { return this . planetaKinoService . login ( { login : login , password : password , } ) . map ( res => { return { code : res . code , message : res . message , data : Mapper . mapToLogin ( res . data ) , } ; } ) . catch ( ( err ) => { return Observable . throw ( { code : err . code , message : err . message , data : undefined } ) ; } ) ; } logout ( ) { return this . planetaKinoService . logout ( ) . map ( res => ( { code : res . code , message : res . message } ) ) . catch ( ( err ) => { return Observable . throw ( { code : err . code , message : err . message , } ) ; } ) ; } getProfile ( ) { return this . planetaKinoService . getProfile ( ) . map ( res => { return { code : res . code , message : res . message , data : { account : Mapper . mapToAccount ( res . data ) , tickets : Mapper . mapToTickets ( res . data ) , } , } ; } ) . catch ( ( err ) => { return Observable . throw ( { code : err . code , message : err . message , data : undefined } ) ; } ) ; ; } sendActivationSms ( phone ) { return this . planetaKinoService . sendActivationSms ( { phone : phone } ) . map ( res => { return { smsCode : res . data . smsCode } ; } ) . catch ( ( err ) => { return Observable . throw ( { code : err . code , message : err . message , } ) ; } ) ; } register ( email , password , smsCode , phone ) { return this . planetaKinoService . register ( { email : email , phone : phone , smsCode : smsCode , password : password , } ) . map ( ( res ) => { return { code : res . code , message : res . message , data : res . data , } ; } ) . catch ( ( err ) => { return Observable . throw ( { code : err . code , message : err . message , } ) ; } ) ; } }