| @@ -34,6 +34,7 @@ import { DashboardComponent } from './pages/dashboard/dashboard.component'; | |||||
| import { FilterViewCardComponent } from './pages/dashboard/filter-view-card/filter-view-card.component'; | import { FilterViewCardComponent } from './pages/dashboard/filter-view-card/filter-view-card.component'; | ||||
| import { NavbarComponent } from './layout/navbar/navbar.component'; | import { NavbarComponent } from './layout/navbar/navbar.component'; | ||||
| import { NotificationsListComponent } from './layout/notifications/notifications-list/notifications-list.component'; | import { NotificationsListComponent } from './layout/notifications/notifications-list/notifications-list.component'; | ||||
| import { HttpClientModule } from '@angular/common/http'; | |||||
| @NgModule({ | @NgModule({ | ||||
| declarations: [ | declarations: [ | ||||
| @@ -73,6 +74,7 @@ import { NotificationsListComponent } from './layout/notifications/notifications | |||||
| AppRoutingModule, | AppRoutingModule, | ||||
| FormsModule, | FormsModule, | ||||
| FileUploadModule, | FileUploadModule, | ||||
| HttpClientModule, | |||||
| ], | ], | ||||
| providers: [], | providers: [], | ||||
| bootstrap: [AppComponent] | bootstrap: [AppComponent] | ||||
| @@ -1,7 +1,5 @@ | |||||
| import { Component, OnInit } from '@angular/core'; | import { Component, OnInit } from '@angular/core'; | ||||
| import { DateInputProperties } from 'src/app/widgets/form/date-input/date-input.component'; | |||||
| import { GenericInputProperties } from 'src/app/widgets/form/generic-input/generic-input.component'; | |||||
| import { SelectInputProperties } from 'src/app/widgets/form/select-input/select-input.component'; | |||||
| import { RegisterBusinessNameService } from 'src/app/services/register-business-name.service'; | |||||
| @Component({ | @Component({ | ||||
| selector: 'app-register-business', | selector: 'app-register-business', | ||||
| @@ -107,7 +105,7 @@ export class RegisterBusinessComponent implements OnInit { | |||||
| value: 'Net Banking', | value: 'Net Banking', | ||||
| }]; | }]; | ||||
| constructor() { } | |||||
| constructor(private registerBusinessNameService: RegisterBusinessNameService) { } | |||||
| ngOnInit(): void { | ngOnInit(): void { | ||||
| } | } | ||||
| @@ -160,21 +158,23 @@ export class RegisterBusinessComponent implements OnInit { | |||||
| }, 1000); | }, 1000); | ||||
| } | } | ||||
| checkName() { | |||||
| async checkName() { | |||||
| this.formState = 'INIT_REGISTER'; | this.formState = 'INIT_REGISTER'; | ||||
| if (this.nameToCheck === `A'DROIT MANAGEMENT SERVICES`) { | |||||
| this.error = { | |||||
| message: this.nameToCheck + ' is unavailable. Entity with identical name exists', | |||||
| isUnique: false, | |||||
| isInvalid: false, | |||||
| }; | |||||
| } else { | |||||
| const nameCheckResponse = await this.registerBusinessNameService.checkName(this.nameToCheck); | |||||
| if (nameCheckResponse.status === `success`) { | |||||
| this.error = { | this.error = { | ||||
| message: this.nameToCheck + ' is available', | message: this.nameToCheck + ' is available', | ||||
| isUnique: true, | isUnique: true, | ||||
| isInvalid: false | isInvalid: false | ||||
| }; | }; | ||||
| } else { | |||||
| this.error = { | |||||
| message: this.nameToCheck + ' is unavailable. ' + nameCheckResponse.status, | |||||
| isUnique: false, | |||||
| isInvalid: false, | |||||
| }; | |||||
| } | } | ||||
| } | } | ||||
| @@ -0,0 +1,16 @@ | |||||
| import { TestBed } from '@angular/core/testing'; | |||||
| import { RegisterBusinessNameService } from './register-business-name.service'; | |||||
| describe('RegisterBusinessNameService', () => { | |||||
| let service: RegisterBusinessNameService; | |||||
| beforeEach(() => { | |||||
| TestBed.configureTestingModule({}); | |||||
| service = TestBed.inject(RegisterBusinessNameService); | |||||
| }); | |||||
| it('should be created', () => { | |||||
| expect(service).toBeTruthy(); | |||||
| }); | |||||
| }); | |||||
| @@ -0,0 +1,26 @@ | |||||
| import { Injectable } from '@angular/core'; | |||||
| import { HttpClient, HttpHeaders } from '@angular/common/http'; | |||||
| import { Observable, throwError } from 'rxjs'; | |||||
| import { catchError, retry } from 'rxjs/operators'; | |||||
| export interface NameCheckResponse { | |||||
| status: string; | |||||
| } | |||||
| @Injectable({ | |||||
| providedIn: 'root' | |||||
| }) | |||||
| export class RegisterBusinessNameService { | |||||
| constructor(private http: HttpClient) { | |||||
| } | |||||
| checkName(name: string) { | |||||
| const nameRequest = { | |||||
| name, | |||||
| }; | |||||
| return this.http.post<NameCheckResponse>('http://localhost:10000/name-check/', nameRequest).toPromise(); | |||||
| } | |||||
| } | |||||