Skip to content

Commit

Permalink
rename register2 services to register
Browse files Browse the repository at this point in the history
  • Loading branch information
auumgn committed Jan 22, 2025
1 parent 0cb0b1b commit ef37af8
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 738 deletions.
4 changes: 2 additions & 2 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ const routes: Routes = [
path: ApplicationRoutes.register,
canActivateChild: [LanguageGuard, RegisterGuard],
loadChildren: () =>
import('./register2/register.module').then((m) => m.RegisterModule),
import('./register/register.module').then((m) => m.RegisterModule),
},
{
path: ApplicationRoutes.search,
Expand Down Expand Up @@ -151,7 +151,7 @@ const routes: Routes = [
matcher: routerReactivation,
canActivateChild: [LanguageGuard, RegisterGuard],
loadChildren: () =>
import('./register2/register.module').then((m) => m.RegisterModule),
import('./register/register.module').then((m) => m.RegisterModule),
},
{
path: ApplicationRoutes.selfService,
Expand Down
23 changes: 15 additions & 8 deletions src/app/core/register/register.backend-validators.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { HttpClient } from '@angular/common/http'
import {
UntypedFormGroup,
AsyncValidatorFn,
AbstractControl,
AsyncValidatorFn,
UntypedFormGroup,
ValidationErrors,
} from '@angular/forms'
import { RegisterForm } from 'src/app/types/register.endpoint'
import { Constructor } from 'src/app/types'
import { Observable, of } from 'rxjs'
import { catchError, map, retry } from 'rxjs/operators'
import { Constructor } from 'src/app/types'
import { RegisterForm } from 'src/app/types/register.endpoint'
import { environment } from 'src/environments/environment'
import { retry, catchError, map } from 'rxjs/operators'
import { HttpClient } from '@angular/common/http'
import { ErrorHandlerService } from '../error-handler/error-handler.service'

interface HasHttpClientAndErrorHandler {
Expand All @@ -23,7 +23,9 @@ interface HasFormAdapters {
formGroupToFullRegistrationForm(
StepA: UntypedFormGroup,
StepB: UntypedFormGroup,
StepC: UntypedFormGroup
StepC: UntypedFormGroup,
StepC2: UntypedFormGroup,
StepD: UntypedFormGroup
): RegisterForm
}

Expand Down Expand Up @@ -160,12 +162,17 @@ export function RegisterBackendValidatorMixin<
StepA: UntypedFormGroup,
StepB: UntypedFormGroup,
StepC: UntypedFormGroup,
StepC2: UntypedFormGroup,
StepD: UntypedFormGroup,

type?: 'shibboleth'
): Observable<RegisterForm> {
const registerForm = this.formGroupToFullRegistrationForm(
StepA,
StepB,
StepC
StepC,
StepC2,
StepD
)
return this._http
.post<RegisterForm>(`${environment.API_WEB}register.json`, registerForm)
Expand Down
57 changes: 50 additions & 7 deletions src/app/core/register/register.form-adapter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UntypedFormGroup } from '@angular/forms'
import { RegisterForm } from 'src/app/types/register.endpoint'
import { Value, Visibility } from 'src/app/types/common.endpoint'
import { Constructor } from 'src/app/types'
import { Value, Visibility } from 'src/app/types/common.endpoint'
import { RegisterForm } from 'src/app/types/register.endpoint'

export function RegisterFormAdapterMixin<T extends Constructor<any>>(base: T) {
return class RegisterFormAdapter extends base {
Expand Down Expand Up @@ -116,18 +116,61 @@ export function RegisterFormAdapterMixin<T extends Constructor<any>>(base: T) {
return value
}

formGroupToAffiliationRegisterForm(formGroup: UntypedFormGroup) {
const value = formGroup.controls['organization'].value
const departmentName = formGroup.controls['departmentName'].value
const roleTitle = formGroup.controls['roleTitle'].value
const startDateGroup = formGroup.controls['startDateGroup'].value

if (typeof value === 'string') {
return { affiliationName: { value } }
} else {
return {
affiliationName: { value: value.value },
disambiguatedAffiliationSourceId: {
value: value.disambiguatedAffiliationIdentifier,
},
orgDisambiguatedId: {
value: value.disambiguatedAffiliationIdentifier,
},
departmentName: { value: departmentName },
roleTitle: { value: roleTitle },
affiliationType: { value: 'employment' },
startDate: {
month: startDateGroup.startDateMonth,
year: startDateGroup.startDateYear,
},
sourceId: { value: value.sourceId },
city: { value: value.city },
region: { value: value.region },
country: { value: value.country },
}
}
}

formGroupToFullRegistrationForm(
StepA: UntypedFormGroup,
StepB: UntypedFormGroup,
StepC: UntypedFormGroup
StepC: UntypedFormGroup,
StepC2: UntypedFormGroup,
StepD: UntypedFormGroup
): RegisterForm {
return {
const value = {
...StepA.value.personal,
...StepB.value.password,
...StepB.value.sendOrcidNews,
...StepC.value.activitiesVisibilityDefault,
...StepC.value.termsOfUse,
...StepC.value.captcha,
...StepD.value.sendOrcidNews,
...StepD.value.termsOfUse,
...StepD.value.captcha,
}

if (StepC2.valid) {
return {
...value,
...StepC2.value.affiliations,
}
} else {
return value
}
}
}
Expand Down
36 changes: 0 additions & 36 deletions src/app/core/register/register.service.spec.ts

This file was deleted.

23 changes: 17 additions & 6 deletions src/app/core/register/register.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { HttpClient } from '@angular/common/http'
import { Injectable } from '@angular/core'
import { UntypedFormGroup } from '@angular/forms'
import { Observable } from 'rxjs'
import { catchError, first, map, retry, switchMap } from 'rxjs/operators'
import { Observable, throwError } from 'rxjs'
import { catchError, first, map, retry, switchMap, tap } from 'rxjs/operators'
import { PlatformInfo, PlatformInfoService } from 'src/app/cdk/platform-info'
import { RequestInfoForm } from 'src/app/types'
import {
Expand All @@ -12,13 +12,14 @@ import {
} from 'src/app/types/register.endpoint'
import { environment } from 'src/environments/environment'

import { ERROR_REPORT } from 'src/app/errors'
import { objectToUrlParameters } from '../../constants'
import { ReactivationLocal } from '../../types/reactivation.local'
import { ErrorHandlerService } from '../error-handler/error-handler.service'
import { UserService } from '../user/user.service'
import { RegisterBackendValidatorMixin } from './register.backend-validators'
import { RegisterFormAdapterMixin } from './register.form-adapter'
import { ERROR_REPORT } from 'src/app/errors'
import { objectToUrlParameters } from '../../constants'
import { ReactivationLocal } from '../../types/reactivation.local'
import { EmailCategoryEndpoint } from 'src/app/types/register.email-category'

// Mixing boiler plate

Expand Down Expand Up @@ -74,10 +75,18 @@ export class RegisterService extends _RegisterServiceMixingBase {
.pipe(map((form) => (this.backendRegistrationForm = form)))
}

getEmailCategory(email: string): Observable<EmailCategoryEndpoint> {
return this._http.get<any>(
`${environment.API_WEB}email-domain/find-category?domain=${email}`
)
}

register(
StepA: UntypedFormGroup,
StepB: UntypedFormGroup,
StepC: UntypedFormGroup,
StepC2: UntypedFormGroup,
StepD: UntypedFormGroup,
reactivation: ReactivationLocal,
requestInfoForm?: RequestInfoForm,
updateUserService = true
Expand All @@ -87,7 +96,9 @@ export class RegisterService extends _RegisterServiceMixingBase {
const registerForm = this.formGroupToFullRegistrationForm(
StepA,
StepB,
StepC
StepC,
StepC2,
StepD
)
this.addOauthContext(registerForm, requestInfoForm)
return this._platform.get().pipe(
Expand Down
Loading

0 comments on commit ef37af8

Please sign in to comment.