import { Injectable } from "@angular/core"; import { TrackService } from "../services/trackService"; import { Utility } from "./utility"; import { IRslt, TaxTable, Track } from "../../public-api"; import { TaxService } from "../services/taxService"; /** * Exposes the User endpoint * */ @Injectable({ providedIn: 'root' }) export class TaxState { taxes!:Array; constructor(private service:TaxService, private utility:Utility) { } get(error:any) { const self = this; this.service.get().subscribe({ next(rslt: { results: TaxTable[]; }) { if (rslt) { self.utility.update(self.taxes, rslt.results) } }, error(e) { }, complete() { } }) } getByID(id: string, done:any, error:any) { const self = this; this.service.getByID(id).subscribe({ next(rslt: IRslt) { if (rslt) { self.utility.updateRslt(self.taxes, rslt) } }, error(e) { error(e) }, complete() { done() } }) } post(track: TaxTable,done:any, error:any) { const self = this; this.service.post(track).subscribe({ next(rslt: IRslt) { if (rslt) { self.utility.updateRslt(self.taxes, rslt) } }, error(e) { error(e) }, complete() { done() } }) } put(track: TaxTable, done:any) { const self = this; this.service.put(track).subscribe({ next(rslt: IRslt) { if (rslt) { self.utility.updateRslt(self.taxes, rslt) } }, error(e) { }, complete() { done(); } }) } delete(track: TaxTable, done:any) { const self = this; this.service.delete(track).subscribe({ next(rslt: { results: TaxTable[]; }) { if (rslt) { rslt.results.forEach((f:TaxTable) => { const index = self.taxes.findIndex(fi => f._id === fi._id); if(index >=0){ self.taxes.splice(index,1) } }) } }, error(e) { done(); }, complete() { done(); } }) } }