import { Injectable } from "@angular/core"; import { ProductService } from "../services/productService"; import { Utility } from "./utility"; import { IRslt, Product } from "../../public-api"; @Injectable({ providedIn: 'root' }) export class ProductState { products: Array; constructor(private service: ProductService, private utility:Utility) { this.products = new Array(); } get(done:any,error:any) { const self = this; this.service.get().subscribe({ next(rslt) { const data = rslt as IRslt if (data) { self.utility.update(self.products, rslt.results) } done() }, error(e) { error(e) }, complete() { } }) } getAll(done:any,error:any) { const self = this; this.service.getAll().subscribe({ next(rslt) { const data = rslt as IRslt if (data) { done(data.results) // self.utility.update(self.products, rslt.results) } done() }, error(e) { error(e) }, complete() { } }) } getID(id: string, done: any,error:any) { const self = this; this.service.getByID(id).subscribe({ next(rslt) { const data = rslt as IRslt // if (data) { // self.utility.update(self.products, rslt.results) // } done(data.results) }, error(e) { error(e) }, complete() { } }) } post(product: Product, done: any,error:any) { const self = this; this.service.post(product).subscribe({ next(rslt) { const data = rslt as IRslt // if (data) { // self.utility.update(self.products, rslt.results) // } done(data.results) }, error(e) { error(e) }, complete() { } }) } put(product: Product, done: any,error:any) { const self = this; this.service.put(product).subscribe({ next(rslt) { const data = rslt as IRslt // if (data) { // self.utility.update(self.products, rslt.results) // } done(rslt.results) }, error(e) { error(e) }, complete() { } }) } delete(product: Product, done: any,error:any) { const self = this; this.service.delete(product).subscribe({ next(rslt) { const data = rslt as IRslt // if (data) { // self.utility.update(self.products, rslt.results) // } done(rslt.results) }, error(e) { error(e) }, complete() { } }) } }