diff --git a/angular/src/app/app.module.ts b/angular/src/app/app.module.ts index be101cf..b689d55 100644 --- a/angular/src/app/app.module.ts +++ b/angular/src/app/app.module.ts @@ -52,6 +52,7 @@ import { MatBottomSheetModule, MatBottomSheetRef, } from '@angular/material/bottom-sheet'; +import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; @NgModule({ declarations: [ @@ -109,6 +110,7 @@ import { MatInputModule, MatSnackBarModule, MatBottomSheetModule, + MatProgressSpinnerModule ], providers: [ DialogService, diff --git a/angular/src/app/pages/guest-card/guest-card.component.html b/angular/src/app/pages/guest-card/guest-card.component.html index 41df275..72ea414 100644 --- a/angular/src/app/pages/guest-card/guest-card.component.html +++ b/angular/src/app/pages/guest-card/guest-card.component.html @@ -8,16 +8,21 @@
-
- За период с 11.01.2023 по 31.03.2023 вам начислено - 360 бонусов + Текущий баланс бонусов: + + {{ + getBalanceAmount(user?.customer_info?.walletBalances) + }} + бонусов

@@ -151,3 +156,7 @@ >

+ + + + diff --git a/angular/src/app/pages/guest-card/guest-card.component.ts b/angular/src/app/pages/guest-card/guest-card.component.ts index 5c39173..7500b37 100644 --- a/angular/src/app/pages/guest-card/guest-card.component.ts +++ b/angular/src/app/pages/guest-card/guest-card.component.ts @@ -8,9 +8,7 @@ import { WpJsonService } from 'src/app/services/wp-json.service'; import { environment } from 'src/environments/environment'; import moment from 'moment'; -interface Moment extends moment.Moment { - -} +interface Moment extends moment.Moment {} @Component({ selector: 'app-guest-card', @@ -33,10 +31,14 @@ export class GuestCardComponent implements OnInit { ) {} ngOnInit(): void { - const token = this.cookiesService.getItem('token') - this.customerInfo = this.wpJsonService.getCustomerInfo(environment.systemId, token || '', environment.icardProxy) - this.purchases = this.getPurchases() - // this.purchases.subscribe((value) => console.log(value)); + const token = this.cookiesService.getItem('token'); + this.customerInfo = this.wpJsonService.getCustomerInfo( + environment.systemId, + token || '', + environment.icardProxy + ); + this.purchases = this.getPurchases(); + this.purchases.subscribe((value) => console.log(value)); } qrCodeClick() { @@ -49,20 +51,38 @@ export class GuestCardComponent implements OnInit { } logout() { - const bottomSheet = this._bottomSheet.open(ExitComponent) + const bottomSheet = this._bottomSheet.open(ExitComponent); bottomSheet.afterDismissed().subscribe({ next: (val) => { if (val) { this.deleteToken(); this.router.navigate(['/login']); } - } - }) + }, + }); } - getPurchases(start: Date | Moment = moment().startOf('month'), end: Date | Moment = moment()): Observable { - const token = this.cookiesService.getItem('token') - const delta = moment(end).diff(moment(start), 'days') - return this.wpJsonService.getTransactionsInfo(environment.systemId, token ?? '', environment.icardProxy) + getPurchases( + start: Date | Moment = moment().startOf('month'), + end: Date | Moment = moment() + ): Observable { + const token = this.cookiesService.getItem('token'); + const delta = moment(end).diff(moment(start), 'days'); + return this.wpJsonService.getTransactionsInfo( + environment.systemId, + token ?? '', + environment.icardProxy + ); + } + + getBalanceAmount(loyaltyPrograms: any[]) { + console.log(loyaltyPrograms); + + return loyaltyPrograms.reduce( + (accumulator, currentValue) => { + return accumulator + currentValue.balance + }, + 0 + ); } }