diff --git a/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html b/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html index 42e6a32..88f87b4 100644 --- a/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html +++ b/projects/account/src/app/modules/device/components/card/device-edit-card/device-edit-card.component.html @@ -24,6 +24,9 @@ Name + + Device name in use + Must be unique diff --git a/projects/account/src/app/modules/device/pages/add/add.component.ts b/projects/account/src/app/modules/device/pages/add/add.component.ts index ff1d059..60540d3 100644 --- a/projects/account/src/app/modules/device/pages/add/add.component.ts +++ b/projects/account/src/app/modules/device/pages/add/add.component.ts @@ -41,7 +41,19 @@ export function pairingCodeValidator(deviceService: DeviceService): AsyncValidat return (control: AbstractControl): Observable => { return deviceService.validatePairingCode(control.value).pipe( map((response) => response.isValid ? null : { unknownPairingCode: true }), - catchError(() => null), + catchError(() => null), + ); + }; +} + + +export function deviceNameValidator(deviceService: DeviceService): AsyncValidatorFn { + return (control: AbstractControl): Observable => { + return deviceService.getDevices().pipe( + map((response) => + response.filter(device => device.name === control.value).length > 0 ? {duplicateDeviceName: true} : null + ), + catchError(() => null), ); }; } @@ -102,7 +114,7 @@ export class AddComponent implements OnInit { this.deviceForm = this.formBuilder.group( { city: [this.defaults ? this.defaults.city.name : null, Validators.required], - name: [null, Validators.required], + name: [null, [ Validators.required ], [ deviceNameValidator(this.deviceService) ]], country: [this.defaults ? this.defaults.country.name : null, Validators.required], pairingCode: [ null,