From 28b8fff4dd255a2d30d60f4143dc778d4dc46358 Mon Sep 17 00:00:00 2001 From: genja Date: Mon, 15 Jun 2026 01:41:37 +0200 Subject: [PATCH] added users register component --- service/src/main/inse/account/logic.py | 31 +++++ service/src/main/inse/account/service.py | 47 ++++++- .../app/api/api/iNSEAccountService.service.ts | 95 +++++++++++-- webapp/src/app/api/model/bodyCreateUser.ts | 19 +++ webapp/src/app/api/model/models.ts | 2 + webapp/src/app/app.routes.ts | 7 + .../app-login/app-login.component.html | 6 + .../app-login/app-login.component.scss | 2 +- .../modules/app-login/app-login.component.ts | 3 +- .../app-register/app-register.component.html | 97 +++++++++++++ .../app-register/app-register.component.scss | 56 ++++++++ .../app-register/app-register.component.ts | 131 ++++++++++++++++++ 12 files changed, 479 insertions(+), 17 deletions(-) create mode 100644 webapp/src/app/api/model/bodyCreateUser.ts create mode 100644 webapp/src/app/modules/app-register/app-register.component.html create mode 100644 webapp/src/app/modules/app-register/app-register.component.scss create mode 100644 webapp/src/app/modules/app-register/app-register.component.ts diff --git a/service/src/main/inse/account/logic.py b/service/src/main/inse/account/logic.py index 96257b7e..b443254c 100644 --- a/service/src/main/inse/account/logic.py +++ b/service/src/main/inse/account/logic.py @@ -33,3 +33,34 @@ def validate_user(username: str, password: str) -> typing.Optional[model.User]: if user and user.password == password: return user return None + +def create_user(username, password, email, institution, superadmin) -> typing.Optional[model.User]: + ''' Adds a new user to the user configuration file. ''' + users = _get_users() + if any(u.username == username for u in users): + logger.warning("Attempt to create duplicate user: %s", username) + return None + + # Determine new IDs + next_account = max((u.account for u in users), default=0) + 1 + next_org = max((u.organization for u in users), default=0) + 1 + + new_user = model.User( + username=username, + password=password, + email=email, + account=next_account, + organization=next_org, + organization_name=institution, + superadmin=superadmin + ) + + users.append(new_user) + user_file = model.UserFile(users=users) + try: + with open('../data/users.json', 'w') as file: + file.write(user_file.model_dump_json(indent=4)) + return new_user + except Exception as e: + logger.error('Could not write user configuration file.', exc_info=e) + return None diff --git a/service/src/main/inse/account/service.py b/service/src/main/inse/account/service.py index 7e67bb19..ae99cd7b 100644 --- a/service/src/main/inse/account/service.py +++ b/service/src/main/inse/account/service.py @@ -27,6 +27,7 @@ router = fastapi.APIRouter( @router.post( "/auth/id", + operation_id="getIdentityGrant", responses={ HTTP_200_OK: {"model": model.IdentityGrant}, HTTP_400_BAD_REQUEST: { @@ -55,7 +56,11 @@ async def get_identity_grant( exp = 12 * 60 * 60 token = security.id_token(user, exp=exp) account = model.AuthAccount( - i=user.account, l=user.username, o=user.organization + i=user.account, + l=user.username, + o=user.organization, + e=user.email, + on=user.organization_name, ) scope = model.AuthScope(t="ID", a=account, d=None, r=[]) grant = model.IdentityGrant( @@ -70,6 +75,7 @@ async def get_identity_grant( @router.post( "/auth/access", + operation_id="getAccessGrant", responses={ HTTP_200_OK: {"model": model.AccessGrant}, HTTP_400_BAD_REQUEST: { @@ -104,7 +110,11 @@ async def get_access_grant( token = security.access_token(user, exp=exp) refresh = security.refresh_token(user, exp=exp) auth_account = model.AuthAccount( - i=user.account, l=user.username, o=user.organization + i=user.account, + l=user.username, + o=user.organization, + e=user.email, + on=user.organization_name, ) scope = model.AuthScope( t="ACCESS", @@ -124,3 +134,36 @@ async def get_access_grant( except Exception as e: logger.error("Token generation failed (%s).", user.username, exc_info=e) raise fastapi.HTTPException(status_code=HTTP_500_INTERNAL_SERVER_ERROR) + + +@router.post( + "/create", + operation_id="createUser", + responses={ + HTTP_200_OK: {"model": model.User}, + HTTP_400_BAD_REQUEST: { + "model": None, + "description": "User creation failed (e.g. duplicate username).", + }, + HTTP_500_INTERNAL_SERVER_ERROR: { + "model": None, + "description": "Internal server error.", + }, + }, +) +async def create_user( + username: typing.Annotated[str, fastapi.Body()], + password: typing.Annotated[str, fastapi.Body()], + email: typing.Annotated[str, fastapi.Body()], + institution: typing.Annotated[str, fastapi.Body()], + superadmin: typing.Annotated[bool, fastapi.Body()] = False, +): + user = logic.create_user(username, password, email, institution, superadmin) + if user is None: + logger.info("User creation failed for (%s).", username) + raise fastapi.HTTPException( + status_code=HTTP_400_BAD_REQUEST, + detail="User creation failed. Username might already exist." + ) + logger.info("User created successfully (%s).", username) + return user diff --git a/webapp/src/app/api/api/iNSEAccountService.service.ts b/webapp/src/app/api/api/iNSEAccountService.service.ts index 7b43eaa5..90181dbd 100644 --- a/webapp/src/app/api/api/iNSEAccountService.service.ts +++ b/webapp/src/app/api/api/iNSEAccountService.service.ts @@ -19,9 +19,13 @@ import { Observable } from 'rxjs'; // @ts-ignore import { AccessGrant } from '../model/accessGrant'; // @ts-ignore +import { BodyCreateUser } from '../model/bodyCreateUser'; +// @ts-ignore import { HTTPValidationError } from '../model/hTTPValidationError'; // @ts-ignore import { IdentityGrant } from '../model/identityGrant'; +// @ts-ignore +import { User } from '../model/user'; // @ts-ignore import { BASE_PATH, COLLECTION_FORMATS } from '../variables'; @@ -39,6 +43,71 @@ export class INSEAccountServiceService extends BaseService { super(basePath, configuration); } + /** + * Create User + * @endpoint post /inse-account/create + * @param bodyCreateUser + * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. + * @param reportProgress flag to report request and response progress. + */ + public createUser(bodyCreateUser: BodyCreateUser, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public createUser(bodyCreateUser: BodyCreateUser, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public createUser(bodyCreateUser: BodyCreateUser, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public createUser(bodyCreateUser: BodyCreateUser, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + if (bodyCreateUser === null || bodyCreateUser === undefined) { + throw new Error('Required parameter bodyCreateUser was null or undefined when calling createUser.'); + } + + let localVarHeaders = this.defaultHeaders; + + const localVarHttpHeaderAcceptSelected: string | undefined = options?.httpHeaderAccept ?? this.configuration.selectHeaderAccept([ + 'application/json' + ]); + if (localVarHttpHeaderAcceptSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Accept', localVarHttpHeaderAcceptSelected); + } + + const localVarHttpContext: HttpContext = options?.context ?? new HttpContext(); + + const localVarTransferCache: boolean = options?.transferCache ?? true; + + + // to determine the Content-Type header + const consumes: string[] = [ + 'application/json' + ]; + const httpContentTypeSelected: string | undefined = this.configuration.selectHeaderContentType(consumes); + if (httpContentTypeSelected !== undefined) { + localVarHeaders = localVarHeaders.set('Content-Type', httpContentTypeSelected); + } + + let responseType_: 'text' | 'json' | 'blob' = 'json'; + if (localVarHttpHeaderAcceptSelected) { + if (localVarHttpHeaderAcceptSelected.startsWith('text')) { + responseType_ = 'text'; + } else if (this.configuration.isJsonMime(localVarHttpHeaderAcceptSelected)) { + responseType_ = 'json'; + } else { + responseType_ = 'blob'; + } + } + + let localVarPath = `/inse-account/create`; + const { basePath, withCredentials } = this.configuration; + return this.httpClient.request('post', `${basePath}${localVarPath}`, + { + context: localVarHttpContext, + body: bodyCreateUser, + responseType: responseType_, + ...(withCredentials ? { withCredentials } : {}), + headers: localVarHeaders, + observe: observe, + ...(localVarTransferCache !== undefined ? { transferCache: localVarTransferCache } : {}), + reportProgress: reportProgress + } + ); + } + /** * Get Access Grant * @endpoint post /inse-account/auth/access @@ -48,18 +117,18 @@ export class INSEAccountServiceService extends BaseService { * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public getAccessGrantInseAccountAuthAccessPost(secret: string, account: number, organization: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public getAccessGrantInseAccountAuthAccessPost(secret: string, account: number, organization: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getAccessGrantInseAccountAuthAccessPost(secret: string, account: number, organization: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getAccessGrantInseAccountAuthAccessPost(secret: string, account: number, organization: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + public getAccessGrant(secret: string, account: number, organization: number, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public getAccessGrant(secret: string, account: number, organization: number, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAccessGrant(secret: string, account: number, organization: number, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getAccessGrant(secret: string, account: number, organization: number, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { if (secret === null || secret === undefined) { - throw new Error('Required parameter secret was null or undefined when calling getAccessGrantInseAccountAuthAccessPost.'); + throw new Error('Required parameter secret was null or undefined when calling getAccessGrant.'); } if (account === null || account === undefined) { - throw new Error('Required parameter account was null or undefined when calling getAccessGrantInseAccountAuthAccessPost.'); + throw new Error('Required parameter account was null or undefined when calling getAccessGrant.'); } if (organization === null || organization === undefined) { - throw new Error('Required parameter organization was null or undefined when calling getAccessGrantInseAccountAuthAccessPost.'); + throw new Error('Required parameter organization was null or undefined when calling getAccessGrant.'); } let localVarHeaders = this.defaultHeaders; @@ -136,15 +205,15 @@ export class INSEAccountServiceService extends BaseService { * @param observe set whether or not to return the data Observable as the body, response or events. defaults to returning the body. * @param reportProgress flag to report request and response progress. */ - public getIdentityGrantInseAccountAuthIdPost(username: string, password: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; - public getIdentityGrantInseAccountAuthIdPost(username: string, password: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getIdentityGrantInseAccountAuthIdPost(username: string, password: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; - public getIdentityGrantInseAccountAuthIdPost(username: string, password: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { + public getIdentityGrant(username: string, password: string, observe?: 'body', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable; + public getIdentityGrant(username: string, password: string, observe?: 'response', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getIdentityGrant(username: string, password: string, observe?: 'events', reportProgress?: boolean, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable>; + public getIdentityGrant(username: string, password: string, observe: any = 'body', reportProgress: boolean = false, options?: {httpHeaderAccept?: 'application/json', context?: HttpContext, transferCache?: boolean}): Observable { if (username === null || username === undefined) { - throw new Error('Required parameter username was null or undefined when calling getIdentityGrantInseAccountAuthIdPost.'); + throw new Error('Required parameter username was null or undefined when calling getIdentityGrant.'); } if (password === null || password === undefined) { - throw new Error('Required parameter password was null or undefined when calling getIdentityGrantInseAccountAuthIdPost.'); + throw new Error('Required parameter password was null or undefined when calling getIdentityGrant.'); } let localVarHeaders = this.defaultHeaders; diff --git a/webapp/src/app/api/model/bodyCreateUser.ts b/webapp/src/app/api/model/bodyCreateUser.ts new file mode 100644 index 00000000..76caab3b --- /dev/null +++ b/webapp/src/app/api/model/bodyCreateUser.ts @@ -0,0 +1,19 @@ +/** + * Innovation Search Engine API + * + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +export interface BodyCreateUser { + username: string; + password: string; + email: string; + institution: string; + superadmin?: boolean; +} + diff --git a/webapp/src/app/api/model/models.ts b/webapp/src/app/api/model/models.ts index 8caaecfd..7b37e6c3 100644 --- a/webapp/src/app/api/model/models.ts +++ b/webapp/src/app/api/model/models.ts @@ -16,6 +16,7 @@ export * from './autocompleteResponse'; export * from './autocompleteResponseMeta'; export * from './autocompleteResponseResultsInner'; export * from './award'; +export * from './bodyCreateUser'; export * from './bundProject'; export * from './bundProjectPage'; export * from './categoryNested'; @@ -74,6 +75,7 @@ export * from './topicSubfield'; export * from './topicsByTime'; export * from './topicsByYear'; export * from './topicsListResponse'; +export * from './user'; export * from './validationError'; export * from './validationErrorLocInner'; export * from './value'; diff --git a/webapp/src/app/app.routes.ts b/webapp/src/app/app.routes.ts index dab2a1f0..9c674dc3 100644 --- a/webapp/src/app/app.routes.ts +++ b/webapp/src/app/app.routes.ts @@ -16,6 +16,13 @@ export const routes: Routes = [ import('./modules/app-login/app-login.component').then( (mod) => mod.AppLoginComponent, ), + }, + { + path: 'register', + loadComponent: () => + import('./modules/app-register/app-register.component').then( + (mod) => mod.AppRegisterComponent, + ), }, { path: 'dashboard', diff --git a/webapp/src/app/modules/app-login/app-login.component.html b/webapp/src/app/modules/app-login/app-login.component.html index 4ebfd0be..957a6b5f 100644 --- a/webapp/src/app/modules/app-login/app-login.component.html +++ b/webapp/src/app/modules/app-login/app-login.component.html @@ -42,6 +42,12 @@ [disabled]="!loginForm.valid || (credentialService.validating | async)"> Anmelden + +
+ +

@if (credentialService.validating | async) { diff --git a/webapp/src/app/modules/app-login/app-login.component.scss b/webapp/src/app/modules/app-login/app-login.component.scss index 56b7c05a..034b92ac 100644 --- a/webapp/src/app/modules/app-login/app-login.component.scss +++ b/webapp/src/app/modules/app-login/app-login.component.scss @@ -37,7 +37,7 @@ } .field { - width: 300px; + width: 400px; } .progress { diff --git a/webapp/src/app/modules/app-login/app-login.component.ts b/webapp/src/app/modules/app-login/app-login.component.ts index 17353a00..24fd129f 100644 --- a/webapp/src/app/modules/app-login/app-login.component.ts +++ b/webapp/src/app/modules/app-login/app-login.component.ts @@ -13,7 +13,7 @@ import { MatIconModule } from '@angular/material/icon'; import { CommonModule } from '@angular/common'; import { Subscription } from 'rxjs'; import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; -import { Router } from '@angular/router'; +import { Router, RouterLink } from '@angular/router'; @Component({ selector: 'app-app-login', @@ -25,6 +25,7 @@ import { Router } from '@angular/router'; MatButtonModule, MatIconModule, MatSnackBarModule, + RouterLink, ], templateUrl: './app-login.component.html', styleUrl: './app-login.component.scss', diff --git a/webapp/src/app/modules/app-register/app-register.component.html b/webapp/src/app/modules/app-register/app-register.component.html new file mode 100644 index 00000000..018be1bf --- /dev/null +++ b/webapp/src/app/modules/app-register/app-register.component.html @@ -0,0 +1,97 @@ +

+
+

Konto erstellen

+

+ Bitte gib Deine Daten ein, um Dich zu registrieren. +

+ + + Benutzername + + @if (registerForm.controls['username'].hasError('required')) { + Fehler: Benutzername erforderlich. + } @else if (registerForm.controls['username'].hasError('minlength')) { + Fehler: Benutzername ist unvollständig. + } + + + + E-Mail + + @if (registerForm.controls['email'].hasError('required')) { + Fehler: E-Mail erforderlich. + } @else if (registerForm.controls['email'].hasError('email')) { + Fehler: Ungültige E-Mail Adresse. + } + + + + Passwort + + @if (showPassword) { + visibility + } @else { + visibility_off + } + @if (registerForm.controls['password'].hasError('required')) { + Fehler: Passwort erforderlich. + } @else if (registerForm.controls['password'].hasError('minlength')) { + Fehler: Passwort ist unvollständig. + } + + + + Institution + + apartment + + @if (registerForm.controls['institution'].hasError('required')) { + Fehler: Institution erforderlich. + } + + @for (institution of institutionOptions(); track institution.id) { + +
{{ institution.display_name }}
+ @if (institution.hint) { + {{ institution.hint }} + } +
+ } +
+
+ +
+ Superadmin Rechte +
+ + + +
+ +
+
+

+ +

+
\ No newline at end of file diff --git a/webapp/src/app/modules/app-register/app-register.component.scss b/webapp/src/app/modules/app-register/app-register.component.scss new file mode 100644 index 00000000..d1585259 --- /dev/null +++ b/webapp/src/app/modules/app-register/app-register.component.scss @@ -0,0 +1,56 @@ +.container { + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + width: 100%; + height: 100%; + background: linear-gradient(160deg, #f4f6fb, #e8ecf7); +} + +.form { + display: flex; + flex-direction: column; + align-items: center; + background: #fff; + border: none; + border-radius: 12px; + box-shadow: + 0 2px 12px #1a3a6e1a, + 0 1px 4px #0000000f; + gap: 20px; + padding: 36px 32px 28px; + + h3 { + margin: 0 0 4px; + font-weight: 600; + color: #1a3a6e; + } +} + +.button { + min-height: 48px; + min-width: 140px; + border-radius: 8px; + font-weight: 500; + letter-spacing: 0.02em; +} + +.field { + width: 400px; +} + +.checkbox-container { + display: flex; + align-items: center; + justify-content: flex-start; +} + +.progress { + padding-top: 5px; + width: 300px; + height: 2em; + text-align: center; + font-size: small; + color: #585f71; +} diff --git a/webapp/src/app/modules/app-register/app-register.component.ts b/webapp/src/app/modules/app-register/app-register.component.ts new file mode 100644 index 00000000..d485ac42 --- /dev/null +++ b/webapp/src/app/modules/app-register/app-register.component.ts @@ -0,0 +1,131 @@ +import { Component, inject, OnDestroy, signal, DestroyRef } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; +import { Router, RouterLink } from '@angular/router'; +import { + FormBuilder, + FormGroup, + ReactiveFormsModule, + Validators, +} from '@angular/forms'; +import { MatButtonModule } from '@angular/material/button'; +import { MatFormFieldModule } from '@angular/material/form-field'; +import { MatInputModule } from '@angular/material/input'; +import { MatIconModule } from '@angular/material/icon'; +import { MatCheckboxModule } from '@angular/material/checkbox'; +import { CredentialService } from '../../shared/services/credential.service'; +import { MatSnackBar, MatSnackBarModule } from '@angular/material/snack-bar'; +import { Subscription, map, switchMap, debounceTime, distinctUntilChanged, catchError,of} from 'rxjs'; +import { MatAutocompleteModule, MatAutocompleteSelectedEvent } from '@angular/material/autocomplete'; +import { InstitutionsService } from '../../api'; +@Component({ + selector: 'app-register', + standalone: true, + imports: [ + CommonModule, + ReactiveFormsModule, + MatButtonModule, + MatFormFieldModule, + MatInputModule, + MatIconModule, + MatCheckboxModule, + RouterLink, + MatSnackBarModule, + MatAutocompleteModule, + ], + templateUrl: './app-register.component.html', + styleUrl: './app-register.component.scss', +}) +export class AppRegisterComponent implements OnDestroy { + private readonly fb = inject(FormBuilder); + protected readonly credentialService = inject(CredentialService); + private readonly router = inject(Router); + private readonly snackBar = inject(MatSnackBar); + private readonly destroyRef = inject(DestroyRef); + private subscription?: Subscription; + private institutionsService = inject(InstitutionsService) + registerForm: FormGroup = this.fb.group({ + username: ['', [Validators.required, Validators.minLength(4)]], + email: ['', [Validators.required, Validators.email]], + password: ['', [Validators.required, Validators.minLength(8)]], + institution: ['', [Validators.required]], + superadmin: [false], + }); + readonly institutionOptions = signal([]); + showPassword = false; + + constructor() { + this.setupInstitutionAutocomplete(); + } + + ngOnDestroy(): void { + this.subscription?.unsubscribe(); + } + + submit() { + if (this.registerForm.valid) { + this.credentialService.validating.next(true); + this.registerForm.disable(); + + this.subscription = this.credentialService + .registerAccount(this.registerForm.value) + .subscribe({ + next: () => { + this.credentialService.validating.next(false); + this.snackBar.open( + 'Konto erfolgreich erstellt! Du kannst Dich jetzt anmelden.', + 'OK', + { duration: 5000 }, + ); + this.router.navigate(['/login']); + }, + error: (err) => { + this.credentialService.validating.next(false); + this.registerForm.enable(); + const message = + err.error?.message || + 'Fehler bei der Registrierung. Bitte versuche es später erneut.'; + this.snackBar.open(message, 'Schließen', { + panelClass: ['error-snackbar'], + duration: 5000, + }); + }, + }); + } + } + + private setupInstitutionAutocomplete(): void { + this.registerForm.controls['institution'].valueChanges + .pipe( + debounceTime(250), + map((value) => (typeof value === 'string' ? value.trim() : '')), + distinctUntilChanged(), + switchMap((query) => { + if (query.length < 2) { + this.institutionOptions.set([]); + return of([]); + } + + return this.searchInstitutions(query).pipe( + catchError((ev) => {console.log(ev);return of([])}), + ); + }), + takeUntilDestroyed(this.destroyRef), + ) + .subscribe((options) => { + this.institutionOptions.set(options); + }); + } + + private searchInstitutions(query: string) { + return this.institutionsService + .autocompleteInstitutions(query, undefined, undefined, 10) + .pipe(map((response) => response.results ?? [])); + } + + onInstitutionSelected(event: MatAutocompleteSelectedEvent): void { + const val = event.option.value; + this.registerForm.controls['institution'].setValue(val, { emitEvent: false }); + this.institutionOptions.set([]); + } +}