import { Injectable } from "@angular/core"; import { Utility } from "./utility"; import { DiscountService } from "../services/discountService"; import { Discount, IRslt } from "../../public-api"; @Injectable({ providedIn: 'root' }) export class DiscountState { discounts:Array = new Array(); constructor(private service: DiscountService, private utility:Utility) { } 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.discounts, 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.discounts, rslt.results) } done() }, error(e) { error(e) }, complete() { } }) } post(invoice: Discount, done: any, error:any) { const self = this; this.service.post(invoice).subscribe({ next(rslt) { const data = rslt as IRslt if (data) { self.utility.update(self.discounts, rslt.results) } done() }, error(e) { }, complete() { } }) } put(invoice: Discount, done: any, error:any) { const self = this; this.service.put(invoice).subscribe({ next(rslt) { const data = rslt as IRslt if (data) { self.utility.update(self.discounts, rslt.results) } done() }, error(e) { error(e) }, complete() { } }) } delete(invoice: Discount, done: any, error:any) { const self = this; this.service.delete(invoice).subscribe({ next(rslt) { const data = rslt as IRslt if (data) { self.utility.update(self.discounts, rslt.results) } done() }, error(e) { error(e) }, complete() { } }) } }