Enhance user API calls

This commit is contained in:
Rene Vergara 2023-05-08 11:49:30 -05:00
parent fe6d27d4a6
commit 83bc383675
Signed by: pitmutt
GPG key ID: 65122AD495A7F5B2

View file

@ -56,12 +56,9 @@ export class UserService{
countries: []
};
private uZaddr = '';
private oZaddr = '';
private uName = '';
private session: string | null = '';
private _uZaddrUpdated: BehaviorSubject<string> = new BehaviorSubject(this.uZaddr);
private _userUpdated: BehaviorSubject<User> = new BehaviorSubject(this.dataStore.user);
private uNameUpdated = new Subject<string>();
private _ownerUpdated: BehaviorSubject<Owner> = new BehaviorSubject(this.dataStore.owner);
private _txsUpdated: BehaviorSubject<Tx[]> = new BehaviorSubject(this.dataStore.txs);
private _paidUpdated: BehaviorSubject<boolean> = 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) => {
obs.subscribe({
next: (responseData) => {
//console.log("Entra a console log");
this.getOwner(this.dataStore.user.address);
}, (error) => {
},
error: (error) => {
//console.log("Status is : [" + error.status + "]");
if ( error.status = 500 ) {
this.notifierService
.showNotification("Invalid Viewing Key, changes not saved!!","Close",'error');
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;
}