добавил регистрацию юзера в айкокард, если его нет
This commit is contained in:
gofnnp 2023-05-17 12:12:25 +04:00
parent 2fa05b391e
commit 6c283812e7
4 changed files with 21 additions and 4 deletions

View File

@ -15,7 +15,7 @@
<div class="guest-card__qr" (click)="qrCodeClick()">
<ng-container *ngIf="customerInfo">
<qr-code
[value]="customerInfo?.phone.substr(2) || 'Данные не найдены'"
[value]="customerInfo?.phone?.substr(2) || 'Данные не найдены'"
[margin]="0"
[size]="qrCodeSize"
errorCorrectionLevel="H"

View File

@ -44,7 +44,7 @@ export class GuestCardComponent implements OnInit {
.subscribe({
next: (value) => {
this.customerInfo = value.customer_info;
this.cookiesService.setCookie('phone-number', this.customerInfo.phone.substr(2))
this.cookiesService.setCookie('phone-number', this.customerInfo?.phone?.substr(2))
this.getPurchases().subscribe((value) => {
this.purchases = this.loyaltyProgram.filterPurchases(value[this.customerInfo?.id])
this.lastPurchase = this.loyaltyProgram.getLastPurchase(this.purchases)

View File

@ -109,6 +109,9 @@ export class LoyaltyProgramService {
getBalanceAmount(loyaltyPrograms: any[]) {
return (loyaltyPrograms || []).reduce((accumulator, currentValue) => {
if (currentValue.wallet.name !== 'Федеральная программа лояльности') {
return accumulator
}
return accumulator + currentValue.balance;
}, 0);
}

View File

@ -2,7 +2,7 @@ import { Injectable } from '@angular/core';
import {environment} from "../../environments/environment";
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {CookiesService} from "./cookies.service";
import {Observable} from "rxjs";
import {Observable, of, switchMap} from "rxjs";
import {JsonRpcBody} from "./jsonrpc.service";
import {DeliveryType, AcceptedOrder, Product} from "../interface/data";
import {ActivatedRoute} from "@angular/router";
@ -43,7 +43,21 @@ export class WpJsonService {
}
getCustomerInfo(systemId: string, token: string, url: string): Observable<any> {
return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url)
return this._request(`customer_info/${systemId}/${token}/`, 'GET', null, false, url).pipe(
switchMap((response) => {
if (response.customer_info.errorCode !== 'Customer_CustomerNotFound') {
return of(response)
} else {
return this.newCustomer(systemId, token, url).pipe(
switchMap(() => this.getCustomerInfo(systemId, token, url))
)
}
})
)
}
newCustomer(systemId: string, token: string, url: string): Observable<any> {
return this._request(`new_customer/${systemId}/${token}/`, 'GET', null, false, url)
}
getTransactions(systemId: string, token: string, url: string, delta?: number): Observable<any> {