import { Injectable } from "@angular/core"; import { CheckoutService } from "../services/checkoutService"; import { Utility } from "./utility"; import { Checkout } from "../../public-api"; /** * Exposes the User endpoint * */ @Injectable({ providedIn: 'root' }) export class CheckoutState { checkouts!: Array; constructor(private checkout: CheckoutService, private utility:Utility) { // this.checkouts = new Array(); } // getCheckouts(featureID: string) { // return this.checkouts.filter(f => f.featureID === featureID); // } get(id:string, done:any, error:any) { this.checkout.getByFeature(id).subscribe({ next(rslt) { if (rslt) { done(rslt.results) } }, error(e) { error(e) }, complete() { } }) } getByID(done:any, error:any) { const self = this; this.checkout.getByID().subscribe({ next(rslt) { if (rslt) { done(rslt.results) // self.utility.updateRslt(self.checkouts, rslt) } }, error(e) { error(e) }, complete() { } }) } post(checkout: Checkout,done:any, error:any) { const self = this; this.checkout.post(checkout).subscribe({ next(rslt) { if (rslt) { done(done.result) // self.utility.updateRslt(self.checkouts, rslt) } }, error(e) { error(e) }, complete() { } }) } put(checkout: Checkout, done:any, error:any) { const self = this; this.checkout.put(checkout).subscribe({ next(rslt) { if (rslt) { done(rslt.results) // self.utility.updateRslt(self.checkouts, rslt) } }, error(e) { error(e) }, complete() { } }) } delete(checkout: Checkout, done:any, error:any) { const self = this; this.checkout.delete(checkout).subscribe({ next(rslt) { if (rslt) { done(rslt.results) // rslt.results.forEach((f:Checkout) => { // const index = self.checkouts.findIndex(fi => f._id === fi._id); // if(index >=0){ // self.checkouts.splice(index,1) // } // }) } }, error(e) { error(e) }, complete() { } }) } }