import { Injectable } from '@angular/core' ; import { HttpClient } from '@angular/common/http' ; import { Observable } from 'rxjs/Observable' ; import { catchError } from 'rxjs/operators' ; import 'rxjs/add/observable/throw' ; import { Pizza } from '../models/pizza.model' ; @ Injectable ( ) export class PizzasService { constructor ( private http ) { } getPizzas ( ) { return this . http . get < Pizza [ ] > ( `/api/pizzas` ) . pipe ( catchError ( ( error ) => Observable . throw ( error . json ( ) ) ) ) ; } createPizza ( payload ) { return this . http . post < Pizza > ( `/api/pizzas` , payload ) . pipe ( catchError ( ( error ) => Observable . throw ( error . json ( ) ) ) ) ; } updatePizza ( payload ) { return this . http . put < Pizza > ( `/api/pizzas/${ payload . id }` , payload ) . pipe ( catchError ( ( error ) => Observable . throw ( error . json ( ) ) ) ) ; } removePizza ( payload ) { return this . http . delete < any > ( `/api/pizzas/${ payload . id }` ) . pipe ( catchError ( ( error ) => Observable . throw ( error . json ( ) ) ) ) ; } }