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