diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 7b16793..f65880d 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -56,12 +56,9 @@ export class UserService{ countries: [] }; private uZaddr = ''; - private oZaddr = ''; - private uName = ''; private session: string | null = ''; private _uZaddrUpdated: BehaviorSubject = new BehaviorSubject(this.uZaddr); private _userUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.user); - private uNameUpdated = new Subject(); private _ownerUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.owner); private _txsUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.txs); private _paidUpdated: BehaviorSubject = new BehaviorSubject(this.dataStore.owner.paid); @@ -86,7 +83,8 @@ export class UserService{ } getCountries() { - let obs = this.http.get<{message: string, countries: any}>(this.beUrl+'api/countries', { headers: this.reqHeaders, observe: 'response'}); + const params = new HttpParams().append('session', this.session!); + let obs = this.http.get<{message: string, countries: any}>(this.beUrl+'api/countries', { headers: this.reqHeaders, params: params, observe: 'response'}); obs.subscribe((CountryResponse) => { if (CountryResponse.status == 200) { @@ -133,7 +131,7 @@ export class UserService{ validateUser(pinString:string){ const params = new HttpParams().append('session', this.dataStore.user.session).append('pin', pinString); - let obs = this.http.post(this.beUrl+'api/validateuser', {}, {headers: this.reqHeaders, params: params, observe: 'response'}); + let obs = this.http.post(this.beUrl+'validateuser', {}, {headers: this.reqHeaders, params: params, observe: 'response'}); obs.subscribe((responseData) => { if (responseData.status == 202) { console.log('Pin validated!'); @@ -150,17 +148,20 @@ export class UserService{ addOwner(owner: Owner) { owner.address = this.dataStore.user.address; - let obs = this.http.post(this.beUrl+'api/owner', {payload: owner}, {headers: this.reqHeaders}); + const params = new HttpParams().append('session', this.session!); + let obs = this.http.post(this.beUrl+'api/owner', {payload: owner}, {headers: this.reqHeaders, params: params}); - obs.subscribe((responseData) => { - //console.log("Entra a console log"); - this.getOwner(this.dataStore.user.address); - }, (error) => { - //console.log("Status is : [" + error.status + "]"); - if ( error.status = 500 ) { - this.notifierService - .showNotification("Invalid Viewing Key, changes not saved!!","Close",'error'); - }; + obs.subscribe({ + next: (responseData) => { + //console.log("Entra a console log"); + this.getOwner(this.dataStore.user.address); + }, + error: (error) => { + //console.log("Status is : [" + error.status + "]"); + if ( error.status = 500 ) { + this.notifierService .showNotification("Invalid Viewing Key, changes not saved!!","Close",'error'); + }; + } }); return obs; @@ -168,7 +169,7 @@ export class UserService{ getOwner(address: string) { console.log('getOwner', address); - const ownParams = new HttpParams().append('address', address); + const ownParams = new HttpParams().append('address', address).append('session', this.session!); let obs = this.http.get<{message:string, owner: any}>(this.beUrl+'api/owner', { headers: this.reqHeaders, params: ownParams, observe: 'response'}); obs.subscribe((OwnerDataResponse) => { @@ -187,12 +188,13 @@ export class UserService{ } deleteUser() { - let obs = this.http.delete<{message: string}>(this.beUrl+'api/user/'+this.dataStore.user._id, {headers: this.reqHeaders }); + const params = new HttpParams().append('session', this.session!); + let obs = this.http.delete<{message: string}>(this.beUrl+'api/user/'+this.dataStore.user._id, {headers: this.reqHeaders, params: params }); - obs.subscribe(UserResponse => { + obs.subscribe({next: () => { //console.log('User delete request sent.'); this.findUser(); - }); + }}); return obs; }