|
1 | 1 | import { UntypedFormGroup } from '@angular/forms' |
2 | | -import { RegisterForm } from 'src/app/types/register.endpoint' |
3 | | -import { Value, Visibility } from 'src/app/types/common.endpoint' |
4 | 2 | import { Constructor } from 'src/app/types' |
| 3 | +import { Value, Visibility } from 'src/app/types/common.endpoint' |
| 4 | +import { RegisterForm } from 'src/app/types/register.endpoint' |
5 | 5 |
|
6 | 6 | export function RegisterFormAdapterMixin<T extends Constructor<any>>(base: T) { |
7 | 7 | return class RegisterFormAdapter extends base { |
@@ -116,18 +116,61 @@ export function RegisterFormAdapterMixin<T extends Constructor<any>>(base: T) { |
116 | 116 | return value |
117 | 117 | } |
118 | 118 |
|
| 119 | + formGroupToAffiliationRegisterForm(formGroup: UntypedFormGroup) { |
| 120 | + const value = formGroup.controls['organization'].value |
| 121 | + const departmentName = formGroup.controls['departmentName'].value |
| 122 | + const roleTitle = formGroup.controls['roleTitle'].value |
| 123 | + const startDateGroup = formGroup.controls['startDateGroup'].value |
| 124 | + |
| 125 | + if (typeof value === 'string') { |
| 126 | + return { affiliationName: { value } } |
| 127 | + } else { |
| 128 | + return { |
| 129 | + affiliationName: { value: value.value }, |
| 130 | + disambiguatedAffiliationSourceId: { |
| 131 | + value: value.disambiguatedAffiliationIdentifier, |
| 132 | + }, |
| 133 | + orgDisambiguatedId: { |
| 134 | + value: value.disambiguatedAffiliationIdentifier, |
| 135 | + }, |
| 136 | + departmentName: { value: departmentName }, |
| 137 | + roleTitle: { value: roleTitle }, |
| 138 | + affiliationType: { value: 'employment' }, |
| 139 | + startDate: { |
| 140 | + month: startDateGroup.startDateMonth, |
| 141 | + year: startDateGroup.startDateYear, |
| 142 | + }, |
| 143 | + sourceId: { value: value.sourceId }, |
| 144 | + city: { value: value.city }, |
| 145 | + region: { value: value.region }, |
| 146 | + country: { value: value.country }, |
| 147 | + } |
| 148 | + } |
| 149 | + } |
| 150 | + |
119 | 151 | formGroupToFullRegistrationForm( |
120 | 152 | StepA: UntypedFormGroup, |
121 | 153 | StepB: UntypedFormGroup, |
122 | | - StepC: UntypedFormGroup |
| 154 | + StepC: UntypedFormGroup, |
| 155 | + StepC2: UntypedFormGroup, |
| 156 | + StepD: UntypedFormGroup |
123 | 157 | ): RegisterForm { |
124 | | - return { |
| 158 | + const value = { |
125 | 159 | ...StepA.value.personal, |
126 | 160 | ...StepB.value.password, |
127 | | - ...StepB.value.sendOrcidNews, |
128 | 161 | ...StepC.value.activitiesVisibilityDefault, |
129 | | - ...StepC.value.termsOfUse, |
130 | | - ...StepC.value.captcha, |
| 162 | + ...StepD.value.sendOrcidNews, |
| 163 | + ...StepD.value.termsOfUse, |
| 164 | + ...StepD.value.captcha, |
| 165 | + } |
| 166 | + |
| 167 | + if (StepC2.valid) { |
| 168 | + return { |
| 169 | + ...value, |
| 170 | + ...StepC2.value.affiliations, |
| 171 | + } |
| 172 | + } else { |
| 173 | + return value |
131 | 174 | } |
132 | 175 | } |
133 | 176 | } |
|
0 commit comments