From 890271cd705f3c26308abf208bcf9c5a9af72f58 Mon Sep 17 00:00:00 2001 From: Adwaith Rao Date: Tue, 28 Dec 2021 02:24:16 +0530 Subject: [PATCH] Add a register name service --- src/app/app.module.ts | 2 ++ .../register-business.component.ts | 24 ++++++++--------- .../register-business-name.service.spec.ts | 16 ++++++++++++ .../register-business-name.service.ts | 26 +++++++++++++++++++ 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 src/app/services/register-business-name.service.spec.ts create mode 100644 src/app/services/register-business-name.service.ts diff --git a/src/app/app.module.ts b/src/app/app.module.ts index def2195..911ef12 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -34,6 +34,7 @@ import { DashboardComponent } from './pages/dashboard/dashboard.component'; import { FilterViewCardComponent } from './pages/dashboard/filter-view-card/filter-view-card.component'; import { NavbarComponent } from './layout/navbar/navbar.component'; import { NotificationsListComponent } from './layout/notifications/notifications-list/notifications-list.component'; +import { HttpClientModule } from '@angular/common/http'; @NgModule({ declarations: [ @@ -73,6 +74,7 @@ import { NotificationsListComponent } from './layout/notifications/notifications AppRoutingModule, FormsModule, FileUploadModule, + HttpClientModule, ], providers: [], bootstrap: [AppComponent] diff --git a/src/app/pages/register-business/register-business.component.ts b/src/app/pages/register-business/register-business.component.ts index a17709a..9d153be 100644 --- a/src/app/pages/register-business/register-business.component.ts +++ b/src/app/pages/register-business/register-business.component.ts @@ -1,7 +1,5 @@ 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({ selector: 'app-register-business', @@ -107,7 +105,7 @@ export class RegisterBusinessComponent implements OnInit { value: 'Net Banking', }]; - constructor() { } + constructor(private registerBusinessNameService: RegisterBusinessNameService) { } ngOnInit(): void { } @@ -160,21 +158,23 @@ export class RegisterBusinessComponent implements OnInit { }, 1000); } - checkName() { + async checkName() { 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 = { message: this.nameToCheck + ' is available', isUnique: true, isInvalid: false }; + } else { + this.error = { + message: this.nameToCheck + ' is unavailable. ' + nameCheckResponse.status, + isUnique: false, + isInvalid: false, + }; } } diff --git a/src/app/services/register-business-name.service.spec.ts b/src/app/services/register-business-name.service.spec.ts new file mode 100644 index 0000000..9363440 --- /dev/null +++ b/src/app/services/register-business-name.service.spec.ts @@ -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(); + }); +}); diff --git a/src/app/services/register-business-name.service.ts b/src/app/services/register-business-name.service.ts new file mode 100644 index 0000000..2ee5e1c --- /dev/null +++ b/src/app/services/register-business-name.service.ts @@ -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('http://localhost:10000/name-check/', nameRequest).toPromise(); + } +}