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