import { Injectable } from "@angular/core" ; import { HttpClient , HttpHeaders } from "@angular/common/http" ; import { Observable } from "rxjs/Rx" ; import { ClienteDTO } from "../../models/cliente.dto" ; import { API_CONFIG } from "../../config/api.config" ; import { StorageService } from "../storage.service" ; import { ImageUtilService } from "../image-util.service" ; @ Injectable ( ) export class ClienteService { constructor ( public http , public storage , public imageUtilService ) { } findById ( id ) { return this . http . get ( `${ API_CONFIG . baseUrl }/clientes/${ id }` ) ; } findByEmail ( email ) { return this . http . get ( `${ API_CONFIG . baseUrl }/clientes/email?value=${ email }` ) ; } getImageFromBucket ( id ) { let url = `${ API_CONFIG . bucketBaseUrl }/cp${ id }.jpg` ; return this . http . get ( url , { responseType : 'blob' } ) ; } insert ( obj ) { return this . http . post ( `${ API_CONFIG . baseUrl }/clientes` , obj , { observe : 'response' , responseType : 'text' } ) ; } uploadPicture ( picture ) { let pictureBlob = this . imageUtilService . dataUriToBlob ( picture ) ; let formData = new FormData ( ) ; formData . set ( 'file' , pictureBlob , 'file.png' ) ; return this . http . post ( `${ API_CONFIG . baseUrl }/clientes/picture` , formData , { observe : 'response' , responseType : 'text' } ) ; } }