From d284a736f675e5c53f7296b8fb48a45b2da8df88 Mon Sep 17 00:00:00 2001 From: Rene Vergara Date: Mon, 15 May 2023 09:48:57 -0500 Subject: [PATCH] Services correction for new owner data structure --- src/app/business/business.component.ts | 3 ++- src/app/db-export/db-export.component.ts | 3 ++- src/app/fullnode.service.ts | 3 ++- src/app/header/header.component.ts | 3 ++- .../items/item-list/item-list.component.ts | 3 ++- src/app/listorders/listorders.component.ts | 3 ++- src/app/login/login.component.ts | 3 ++- src/app/order/order.service.ts | 5 +++-- src/app/owner.model.ts | 1 + src/app/pmtservice/pmtservice.component.ts | 3 ++- src/app/receipt.service.ts | 3 ++- src/app/settings/settings.component.ts | 6 +++--- src/app/user.service.ts | 21 ++++++++++++++++--- src/app/viewer/viewer.component.ts | 7 ++++--- src/app/xero.service.ts | 2 -- src/app/xeroreg/xeroreg.component.ts | 3 ++- 16 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/app/business/business.component.ts b/src/app/business/business.component.ts index 64bdf82..8f0f463 100644 --- a/src/app/business/business.component.ts +++ b/src/app/business/business.component.ts @@ -61,7 +61,8 @@ export class BusinessComponent implements OnInit { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' } public countriesUpdate: Observable; public ownerUpdate: Observable; diff --git a/src/app/db-export/db-export.component.ts b/src/app/db-export/db-export.component.ts index 138b48e..81de691 100644 --- a/src/app/db-export/db-export.component.ts +++ b/src/app/db-export/db-export.component.ts @@ -38,7 +38,8 @@ export class DbExportComponent implements OnInit { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; _ordersOk = false; diff --git a/src/app/fullnode.service.ts b/src/app/fullnode.service.ts index e937507..3bea164 100644 --- a/src/app/fullnode.service.ts +++ b/src/app/fullnode.service.ts @@ -39,7 +39,8 @@ export class FullnodeService{ invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; constructor(private http: HttpClient, public userService: UserService){ diff --git a/src/app/header/header.component.ts b/src/app/header/header.component.ts index ca3096b..95dbec2 100644 --- a/src/app/header/header.component.ts +++ b/src/app/header/header.component.ts @@ -33,7 +33,8 @@ export class HeaderComponent implements OnInit, OnDestroy { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; public heightUpdate: Observable; public ownerUpdate: Observable; diff --git a/src/app/items/item-list/item-list.component.ts b/src/app/items/item-list/item-list.component.ts index e3bb5b6..cb83e0b 100644 --- a/src/app/items/item-list/item-list.component.ts +++ b/src/app/items/item-list/item-list.component.ts @@ -46,7 +46,8 @@ export class ItemListComponent implements OnInit{ invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; public ownerUpdate: Observable; diff --git a/src/app/listorders/listorders.component.ts b/src/app/listorders/listorders.component.ts index 8d90f35..adc2202 100644 --- a/src/app/listorders/listorders.component.ts +++ b/src/app/listorders/listorders.component.ts @@ -59,7 +59,8 @@ export class ListOrdersComponent implements OnInit, OnDestroy{ invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; zecPrice: number = 1; nodeAddress: string = ''; diff --git a/src/app/login/login.component.ts b/src/app/login/login.component.ts index 5b4616e..b39838e 100644 --- a/src/app/login/login.component.ts +++ b/src/app/login/login.component.ts @@ -48,7 +48,8 @@ export class LoginComponent implements OnInit, AfterViewInit { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; private FullnodeSub: Subscription = new Subscription(); private UserSub: Subscription = new Subscription(); diff --git a/src/app/order/order.service.ts b/src/app/order/order.service.ts index ad0732d..75cded0 100644 --- a/src/app/order/order.service.ts +++ b/src/app/order/order.service.ts @@ -40,7 +40,8 @@ export class OrderService { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }, order: { address: '', @@ -207,7 +208,7 @@ export class OrderService { }); this.dataStore.order.closed = true; this.dataStore.order.paid = paid; - let obs = this.http.post(this.beUrl+'api/order', {payload: this.dataStore.order}, { headers: this.reqHeaders }); + let obs = this.http.post(this.beUrl+'api/order', {payload: this.dataStore.order}, { headers: this.reqHeaders, params: this.reqParams }); obs.subscribe((orderData) => { console.log('Closed order', orderData); this.dataStore.order = { diff --git a/src/app/owner.model.ts b/src/app/owner.model.ts index 6e13d54..aacc7a8 100644 --- a/src/app/owner.model.ts +++ b/src/app/owner.model.ts @@ -13,4 +13,5 @@ export interface Owner { expiration: string; payconf: boolean; crmToken: string; + viewkey: string; } diff --git a/src/app/pmtservice/pmtservice.component.ts b/src/app/pmtservice/pmtservice.component.ts index 0318f7b..4d014fa 100644 --- a/src/app/pmtservice/pmtservice.component.ts +++ b/src/app/pmtservice/pmtservice.component.ts @@ -68,7 +68,8 @@ export class PmtserviceComponent implements OnInit { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; public order: Order = { diff --git a/src/app/receipt.service.ts b/src/app/receipt.service.ts index d17262b..1701ff5 100644 --- a/src/app/receipt.service.ts +++ b/src/app/receipt.service.ts @@ -29,7 +29,8 @@ export class ReceiptService { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }, order: { address: '', diff --git a/src/app/settings/settings.component.ts b/src/app/settings/settings.component.ts index a21c7bf..8e775dd 100644 --- a/src/app/settings/settings.component.ts +++ b/src/app/settings/settings.component.ts @@ -127,7 +127,7 @@ export class SettingsComponent implements OnInit { public xeroService: XeroService, public wooService: WoocommerceService, private dialogRef: MatDialogRef, - @Inject(MAT_DIALOG_DATA) public data: {o: Owner, v: string}) { + @Inject(MAT_DIALOG_DATA) public data: {o: Owner}) { this.useZats = data.o.zats; this.useVKey = data.o.payconf; this.settingsForm = fb.group({ @@ -136,7 +136,7 @@ export class SettingsComponent implements OnInit { useZats: [data.o.zats, Validators.required], useVKey: [data.o.payconf, Validators.required], // proVersion: [data.invoices, Validators.required], - vKey: [data.v] + vKey: [data.o.viewkey] }); this.accCodForm = fb.group ({ xAcc: [this.xeroAccCod] @@ -146,7 +146,7 @@ export class SettingsComponent implements OnInit { this.settingsForm.get('vKey')!.enable(); } this.owner = data.o; - this.viewkey = data.v; + this.viewkey = data.o.viewkey; this.proVersion = this.owner.invoices; if ( this.owner.crmToken !== '' ) { this.linked2Xero = true; diff --git a/src/app/user.service.ts b/src/app/user.service.ts index 89cc909..5756115 100644 --- a/src/app/user.service.ts +++ b/src/app/user.service.ts @@ -38,7 +38,8 @@ export class UserService{ invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }, countries: [] }; @@ -140,7 +141,7 @@ export class UserService{ return obs; } - addOwner(oData: {first: string, last: string, phone: string, name: string, street: string, city: string, state: string, postal: string, country: string, email: string, website: string, payconf: boolean}) { + addOwner(oData: {first: string, last: string, phone: string, name: string, street: string, city: string, state: string, postal: string, country: string, email: string, website: string}) { let obs = this.http.post(this.beUrl+'api/owner', {payload: oData}, {headers: this.reqHeaders, params: this.reqParams}); @@ -152,7 +153,7 @@ export class UserService{ 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'); }; } }); @@ -160,6 +161,20 @@ export class UserService{ return obs; } + saveOwnerSettings(o: Owner) { + let obs = this.http.post(this.beUrl + 'api/ownersettings', {payload: o}, {headers: this.reqHeaders, params: this.reqParams}); + obs.subscribe({ + next: () => { + this.getOwner(); + }, + error: (error) => { + if ( error.status == 500 ){ + this.notifierService.showNotification("Saving settings failed", "Close", "error") + } + } + }) + } + getOwner() { //console.log('getOwner', address); //const ownParams = this.reqParams.append('address', address) diff --git a/src/app/viewer/viewer.component.ts b/src/app/viewer/viewer.component.ts index f76d7a6..25c16aa 100644 --- a/src/app/viewer/viewer.component.ts +++ b/src/app/viewer/viewer.component.ts @@ -41,7 +41,8 @@ export class ViewerComponent implements OnInit { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; public price: number = 1; public addrUpdate: Observable; @@ -114,13 +115,13 @@ export class ViewerComponent implements OnInit { dialogConfig.disableClose = true; dialogConfig.autoFocus = true; - dialogConfig.data = {o: this.owner, v: ''}; + dialogConfig.data = {o: this.owner}; const dialogRef = this.dialog.open(SettingsComponent, dialogConfig); dialogRef.afterClosed().subscribe((val) => { if (val != null) { //console.log('Saving settings', val); - //this.userService.addOwner(val); + this.userService.saveOwnerSettings(val); this.fullnodeService.getPrice(val.currency); this.loginCheck(); } diff --git a/src/app/xero.service.ts b/src/app/xero.service.ts index b31b3ad..77ab78b 100644 --- a/src/app/xero.service.ts +++ b/src/app/xero.service.ts @@ -56,9 +56,7 @@ export class XeroService { obs.subscribe(xeroDataResponse => { if (xeroDataResponse.status == 200) { this.clientId = xeroDataResponse.body!.xeroConfig.clientId; - //this.clientSecret = xeroDataResponse.body!.xeroConfig.clientSecret; this._clientIdUpdated.next(Object.assign({}, this).clientId); - //this._clientSecretUpdated.next(Object.assign({}, this).clientSecret); } else { console.log('No config in DB!'); } diff --git a/src/app/xeroreg/xeroreg.component.ts b/src/app/xeroreg/xeroreg.component.ts index 5bd1b0f..2984bf7 100644 --- a/src/app/xeroreg/xeroreg.component.ts +++ b/src/app/xeroreg/xeroreg.component.ts @@ -39,7 +39,8 @@ export class XeroRegComponent implements OnInit { invoices: false, expiration: new Date(Date.now()).toISOString(), payconf: false, - crmToken: '' + crmToken: '', + viewkey: '' }; public ownerUpdate:Observable; public flag: boolean = false;