From 2c9c6f9caee017f86eef5c9ab258cb250d6a82d8 Mon Sep 17 00:00:00 2001 From: InalDjasheev Date: Sat, 12 Dec 2020 12:52:05 +0300 Subject: [PATCH 1/2] Now a user cannot have more than 100 records in the database --- src/app/_services/data.service.ts | 4 ++++ src/app/data/add/add.component.ts | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/src/app/_services/data.service.ts b/src/app/_services/data.service.ts index c586aec..75563ff 100644 --- a/src/app/_services/data.service.ts +++ b/src/app/_services/data.service.ts @@ -25,6 +25,10 @@ export class DataService { return this.httpClient.get(environment.backendUrl + '/data').toPromise(); } + getCount(): Promise { + return this.httpClient.get(environment.backendUrl + '/data/count').toPromise(); + } + add(data: Data): Promise { return this.httpClient.post(environment.backendUrl + '/data', data).toPromise(); } diff --git a/src/app/data/add/add.component.ts b/src/app/data/add/add.component.ts index 126392b..beb2e95 100644 --- a/src/app/data/add/add.component.ts +++ b/src/app/data/add/add.component.ts @@ -12,6 +12,7 @@ import {isNameExists} from '../../_validators/uniq-name.validator'; styleUrls: ['./add.component.scss'] }) export class AddComponent implements OnInit { + dataCount: string; form: FormGroup; inProgress = false; type: FormControl = new FormControl('', Validators.required); @@ -39,6 +40,9 @@ export class AddComponent implements OnInit { } ngOnInit() { + this.dataService.getCount().then(data => { + this.dataCount = data + }) } back() { @@ -47,12 +51,19 @@ export class AddComponent implements OnInit { onSubmit() { this.inProgress = true; - const data = this.form.value; - data.name = this.getFormattedName(); - this.dataService.add(data).then(() => { - this.alertService.success('Data added successfully'); - this.router.navigate(['/data/' + data.name]); - }).finally(() => this.inProgress = false); + + if(+this.dataCount > 7) { + this.alertService.success('You cannot have more than 100 records!'); + this.router.navigate(['/data']); + this.inProgress = false; + } else { + const data = this.form.value; + data.name = this.getFormattedName(); + this.dataService.add(data).then(() => { + this.alertService.success('Data added successfully'); + this.router.navigate(['/data/' + data.name]); + }).finally(() => this.inProgress = false); + } } onTypeChange() { From 5fbadc364ccbd2538e9c91e54bddd1688a5b4b38 Mon Sep 17 00:00:00 2001 From: InalDjasheev Date: Sat, 12 Dec 2020 12:58:25 +0300 Subject: [PATCH 2/2] Fixed issue more than 100 elements in the db; Now a user cannot have more than 100 records in the database; --- src/app/data/add/add.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/data/add/add.component.ts b/src/app/data/add/add.component.ts index beb2e95..d8e4335 100644 --- a/src/app/data/add/add.component.ts +++ b/src/app/data/add/add.component.ts @@ -52,7 +52,7 @@ export class AddComponent implements OnInit { onSubmit() { this.inProgress = true; - if(+this.dataCount > 7) { + if(+this.dataCount > 100) { this.alertService.success('You cannot have more than 100 records!'); this.router.navigate(['/data']); this.inProgress = false;