diff --git a/angular/src/app/interface/data.ts b/angular/src/app/interface/data.ts
index bb1a3e0..7ebe6c9 100644
--- a/angular/src/app/interface/data.ts
+++ b/angular/src/app/interface/data.ts
@@ -203,6 +203,7 @@ export interface UserInfo {
OrdersSum: number;
categories: UserInfoCategory[];
customer_level: number;
+ birthday: string;
id: string;
name: string | null;
phone: string;
@@ -213,3 +214,9 @@ export interface ResponseError {
code: number;
msg: string;
}
+
+export interface UpdateNewCustomerRequest {
+ name: string;
+ sex: string;
+ birthday: string;
+}
diff --git a/angular/src/app/presentation-options/default-option/default-option-routing.module.ts b/angular/src/app/presentation-options/default-option/default-option-routing.module.ts
index 205ee1a..388c3de 100644
--- a/angular/src/app/presentation-options/default-option/default-option-routing.module.ts
+++ b/angular/src/app/presentation-options/default-option/default-option-routing.module.ts
@@ -4,6 +4,7 @@ import { GuestCardComponent } from './pages/guest-card/guest-card.component';
import { AuthGuard } from 'src/app/guards/auth-guard.guard';
import { LoginComponent } from './pages/login/login.component';
import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component';
+import { CreateUserComponent } from './pages/create_user/create_user.component';
const routes: Routes = [
{
@@ -18,7 +19,11 @@ const routes: Routes = [
{
path: 'loyality-program',
component: LoyalityProgramComponent,
- }
+ },
+ {
+ path: 'create_user',
+ component: CreateUserComponent,
+ },
];
@NgModule({
diff --git a/angular/src/app/presentation-options/default-option/default-option.module.ts b/angular/src/app/presentation-options/default-option/default-option.module.ts
index 58cbbf4..940e19b 100644
--- a/angular/src/app/presentation-options/default-option/default-option.module.ts
+++ b/angular/src/app/presentation-options/default-option/default-option.module.ts
@@ -7,6 +7,9 @@ import { SocialMediaButtonsComponent } from './components/social-media-buttons/s
import { NavbarComponent } from './components/navbar/navbar.component';
import { MenuItemComponent } from './components/navbar/menu_item.component';
import { MatIconModule } from '@angular/material/icon';
+import { MatDatepickerModule } from '@angular/material/datepicker';
+import { MatSelectModule } from '@angular/material/select';
+import { MatNativeDateModule } from '@angular/material/core';
import { GuestCardComponent } from './pages/guest-card/guest-card.component';
import { QrCodeModule } from 'ng-qrcode';
import { AccordionComponent } from './components/accordion/accordion.component';
@@ -22,6 +25,7 @@ import { DirectivesModule } from 'src/app/directives/directives.module';
import { LoyalityProgramComponent } from './pages/loyality-program/loyality-program.component';
import { MatButtonModule } from '@angular/material/button';
import { ToastModule } from 'primeng/toast';
+import { CreateUserComponent } from './pages/create_user/create_user.component';
@NgModule({
@@ -37,6 +41,7 @@ import { ToastModule } from 'primeng/toast';
LoginComponent,
LoyalityProgramComponent,
MenuItemComponent,
+ CreateUserComponent,
],
imports: [
ToastModule,
@@ -51,7 +56,10 @@ import { ToastModule } from 'primeng/toast';
ReactiveFormsModule,
MatInputModule,
DirectivesModule,
- MatButtonModule
+ MatButtonModule,
+ MatDatepickerModule,
+ MatSelectModule,
+ MatNativeDateModule,
],
bootstrap: [IndexComponent],
})
diff --git a/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.html b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.html
new file mode 100644
index 0000000..b75af08
--- /dev/null
+++ b/angular/src/app/presentation-options/default-option/pages/create_user/create_user.component.html
@@ -0,0 +1,45 @@
+
Не пришло SMS?
diff --git a/angular/src/app/presentation-options/default-option/pages/login/login.component.ts b/angular/src/app/presentation-options/default-option/pages/login/login.component.ts
index f764e7e..93cfaa6 100644
--- a/angular/src/app/presentation-options/default-option/pages/login/login.component.ts
+++ b/angular/src/app/presentation-options/default-option/pages/login/login.component.ts
@@ -18,7 +18,6 @@ import { MessageService } from 'primeng/api';
export class LoginComponent implements OnInit {
public isShowNumber: boolean = true;
public phoneForm = new FormGroup({
- name: new FormControl('', [Validators.required]),
phone: new FormControl('', [Validators.required]),
});
public codeForm = new FormGroup({
@@ -125,7 +124,7 @@ export class LoginComponent implements OnInit {
const phoneData = this.phoneForm.value;
this.authService.submitCode(
- Object.values(data).join(''), phoneData.phone!, phoneData.name!);
+ Object.values(data).join(''), phoneData.phone!);
}
backToPhoneForm = () => {
diff --git a/angular/src/app/services/auth.service.ts b/angular/src/app/services/auth.service.ts
index 359f596..c47b0c3 100644
--- a/angular/src/app/services/auth.service.ts
+++ b/angular/src/app/services/auth.service.ts
@@ -4,7 +4,7 @@ import { WpJsonService } from './wp-json.service';
import { environment } from 'src/environments/environment';
import { JsonrpcService, RpcService } from './jsonrpc.service';
import { MessageService } from 'primeng/api';
-import { UserInfo, Purchase, lvlPeriod, UserInfoWalletBalance, ResponseError } from '../interface/data';
+import { UserInfo, Purchase, lvlPeriod, UserInfoWalletBalance } from '../interface/data';
import { lvlPeriods } from 'src/app/app.constants';
import moment, { Moment } from 'moment-timezone';
import { Router } from '@angular/router';
@@ -69,7 +69,10 @@ export class AuthService {
)
.subscribe({
next: (value) => {
- if (value && value.error && value.error.code > 1) {
+ if (value && value.customer_info && value.customer_info.errorCode === 'Customer_CustomerNotFound'
+ || !this.userHasData(value?.customer_info)) {
+ this.router.navigate(['create_user']);
+ } else if (value && value.error && value.error.code > 1) {
this.messageService.clear();
this.messageService.add({
severity: 'error',
@@ -90,6 +93,10 @@ export class AuthService {
});
}
+ userHasData(user?: UserInfo) {
+ return user && (user.name || user.birthday);
+ }
+
logout() {
this.userInfo = undefined;
this.cookiesService.logout();
@@ -145,7 +152,7 @@ export class AuthService {
});
}
- submitCode(code: string, phone: string, name: string) {
+ submitCode(code: string, phone: string) {
this.loading = true;
this.jsonrpc
.rpc(
@@ -160,38 +167,9 @@ export class AuthService {
next: (result) => {
if (result.code === 0) {
this.cookiesService.setCookie('token', result?.data?.token);
- this.jsonrpc.rpc(
- {
- method: 'updateAdditionalInfo',
- params: [
- {
- first_name: name,
- birth_day: '01.01.1999'
- },
- ],
- },
- RpcService.authService,
- true
- ).subscribe({
- next: () => {
- this.router.navigate(['/']);
+ this.router.navigate(['/']);
- this.wpJsonService.newCustomer(
- environment.systemId,
- result?.data?.token,
- environment.icardProxy,
- )
- .subscribe({
- next: () => {
- this.getUserInfo();
- }
- })
- },
- error: (err) => {
- console.error(err);
- this.loading = false;
- },
- })
+ this.getUserInfo();
} else if (result.code === 230) {
this.messageService.clear();
this.messageService.add({
@@ -202,7 +180,7 @@ export class AuthService {
},
error: (error) => {
console.error(error);
- this.loading = false;
+ this.loading = false;
},
});
}
@@ -261,4 +239,45 @@ export class AuthService {
return accumulator + currentValue.balance;
}, 0);
}
+
+ register(name: string, sex: string, date: string) {
+ if (this.token) {
+ this.loading = true;
+
+ this.jsonrpc.rpc(
+ {
+ method: 'updateAdditionalInfo',
+ params: [
+ {
+ first_name: name,
+ birth_day: '01.01.1999'
+ },
+ ],
+ },
+ RpcService.authService,
+ true
+ ).subscribe({
+ next: () => {
+ this.wpJsonService.updateNewCustomer(environment.systemId, this.token!, {
+ name,
+ sex: sex,
+ birthday: date,
+ })
+ .subscribe({
+ next: () => {
+ this.router.navigate(['/']);
+ this.getUserInfo();
+ },
+ error: () => {
+ this.loading = false;
+ }
+ });
+ },
+ error: (err) => {
+ console.error(err);
+ this.loading = false;
+ },
+ })
+ }
+ }
}
diff --git a/angular/src/app/services/wp-json.service.ts b/angular/src/app/services/wp-json.service.ts
index c05b001..743d829 100644
--- a/angular/src/app/services/wp-json.service.ts
+++ b/angular/src/app/services/wp-json.service.ts
@@ -4,7 +4,7 @@ import { HttpClient, HttpHeaders } from "@angular/common/http";
import { CookiesService } from "./cookies.service";
import { Observable, of, switchMap } from "rxjs";
import { JsonRpcBody } from "./jsonrpc.service";
-import { DeliveryType, AcceptedOrder, Product } from "../interface/data";
+import { DeliveryType, AcceptedOrder, Product, UpdateNewCustomerRequest } from "../interface/data";
export enum Method {
@@ -59,6 +59,10 @@ export class WpJsonService {
return this._request(`purchase/${systemId}/${token}/${delta || ''}`, 'GET', null, false, url)
}
+ updateNewCustomer(systemId: string, token: string, data: UpdateNewCustomerRequest) {
+ return this._request(`update_new_customer/${systemId}/${token}/`, 'POST', data, false, environment.icardProxy);
+ }
+
// getSiteConfig(): Observable