Browse Source

Add a register name service

master
Adwaith Rao 3 years ago
parent
commit
890271cd70
4 changed files with 56 additions and 12 deletions
  1. +2
    -0
      src/app/app.module.ts
  2. +12
    -12
      src/app/pages/register-business/register-business.component.ts
  3. +16
    -0
      src/app/services/register-business-name.service.spec.ts
  4. +26
    -0
      src/app/services/register-business-name.service.ts

+ 2
- 0
src/app/app.module.ts View File

@@ -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]


+ 12
- 12
src/app/pages/register-business/register-business.component.ts View File

@@ -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,
};
}
}



+ 16
- 0
src/app/services/register-business-name.service.spec.ts View File

@@ -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();
});
});

+ 26
- 0
src/app/services/register-business-name.service.ts View File

@@ -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();
}
}

Loading…
Cancel
Save