import { Injectable } from "@angular/core"; import { UserService } from "../services/userService"; import { IRslt, User } from "../../public-api"; /** * Exposes the User endpoint * */ @Injectable({ providedIn: 'root' }) export class UserState { user: User | undefined | null = null; users:Array = new Array(); constructor(public service: UserService) { } // getToken() { // return this.service.api.token; // } // setToken(token: string) { // this.service.setToken(token) // } // token(done:any){ // const self = this; // this.service.token().subscribe({ // next(n){ // const rslt = n as IRslt; // if(rslt){ // self.user = new User(rslt.results) // } // }, error(e){ // }, complete(){ // done(); // } // }) // } getAll(done:any,error:any) { this.service.getAll().subscribe({ next(n) { const rslt = n as IRslt; done(rslt.results) }, error(e) { error(e) }, complete() { } }) } get(done:any,error:any) { const self = this; this.service.get().subscribe({ next(n) { const rslt = n as IRslt; done(rslt.results) }, error(e) { error(e) }, complete() { } }) } //creation happens only at account creation I think... // post(){ // } put(user: User, done:any, error:any) { const self = this; this.service.put(user).subscribe({ next(rslt) { if (rslt) { done(rslt.results) // self.user = new User(rslt.results) } }, error(e) { error(e) }, complete() { } }) } //not sure why anyone would have access to delete this... // delete(){ // } }