import { Injectable } from "@angular/core"; import { TrackService } from "../services/trackService"; import { Utility } from "./utility"; import { InventoryItem, Track } from "../../public-api"; import { InventoryService } from "../services/inventoryService"; /** * Exposes the User endpoint * */ @Injectable({ providedIn: 'root' }) export class InventoryState { inventories:Array = []; constructor(private service:InventoryService, private utility:Utility) { } get(id:string,error:any) { const self = this; this.service.getByID(id).subscribe({ next(rslt) { if (rslt) { self.utility.update(self.inventories, [rslt.results]) } }, error(e) { }, complete() { } }) } getByID(ids: string[], done:any, error:any) { const self = this; this.service.getByIDs(ids).subscribe({ next(rslt) { if (rslt) { done(rslt.results) // self.utility.updateRslt(self.inventories, rslt) } else { error() } }, error(e) { error(e) }, complete() { } }) } post(inventory: InventoryItem,done:any, error:any) { const self = this; this.service.post(inventory).subscribe({ next(rslt) { // if (rslt) { // self.utility.updateRslt(self.inventories, rslt) // } done(rslt.results) }, error(e) { error(e) }, complete() { } }) } postMany(inventories: InventoryItem[],done:any, err:any) { const self = this; this.service.postMany(inventories).subscribe({ next(rslt) { // if (rslt) { // self.utility.updateRslt(self.inventories, rslt) // } done(rslt.results) }, error(e) { err(e) }, complete() { } }) } put(inventory: InventoryItem, done:any, err:any) { const self = this; this.service.put(inventory).subscribe({ next(rslt) { // if (rslt) { // self.utility.updateRslt(self.inventories, rslt) // } done(rslt.results) }, error(e) { err(e) }, complete() { } }) } clear(id:string,done:any, err:any){ this.service.clear(id).subscribe({ next(rslt) { done(rslt.results) }, error(e) { err(e) }, complete() { } }) } delete(id: string, done:any, error:any) { const self = this; this.service.delete(id).subscribe({ next(rslt) { // if (rslt) { done(rslt?.results) // rslt.results.forEach((f:InventoryItem) => { // const index = self.inventories.findIndex(fi => f._id === fi._id); // if(index >=0){ // self.inventories.splice(index,1) // } // }) // } }, error(e) { error(e) }, complete() { } }) } }