Skip to content

Commit

Permalink
Allow backend validation but not resolution (#2114)
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro authored Dec 7, 2023
1 parent 60958f7 commit a1c01bc
Showing 1 changed file with 42 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,60 +266,52 @@ export class WorkFormComponent implements OnInit {
formGroup: UntypedFormGroup,
externalIdentifierType: string
): AsyncValidatorFn {
return (control: AbstractControl) => {
if (externalIdentifierType === 'isbn') {
if (!(control.value?.length === 10 || control.value?.length === 13)) {
return of({ validFormat: true })
} else {
return of(null)
}
} else {
return this._workService
.validateWorkIdTypes(externalIdentifierType, control.value)
.pipe(
map((value) => {
if (
(formGroup.controls.externalIdentifierUrl?.value?.length > 0 &&
formGroup.controls.externalIdentifierUrl.value !==
formGroup.controls.externalIdentifierUrlWasBackendGenerated
.value) ||
formGroup.controls.externalIdentifierId.value ===
formGroup.controls.externalIdentifierIdStored.value
) {
// do not overwrite the existing URL
} else if (
value.generatedUrl &&
value.generatedUrl !==
formGroup.controls.externalIdentifierUrl.value
) {
formGroup.controls.externalIdentifierUrl.setValue(
decodeURI(value.generatedUrl)
)
formGroup.controls.externalIdentifierUrlWasBackendGenerated.setValue(
decodeURI(value.generatedUrl)
)
} else if (
!value.validFormat ||
(value.attemptedResolution && !value.resolved)
) {
if (!this.work?.putCode) {
formGroup.controls.externalIdentifierUrl.setValue('')
}
return (control: AbstractControl) => {
return this._workService
.validateWorkIdTypes(externalIdentifierType, control.value)
.pipe(
map((value) => {
if (
(formGroup.controls.externalIdentifierUrl?.value?.length > 0 &&
formGroup.controls.externalIdentifierUrl.value !==
formGroup.controls.externalIdentifierUrlWasBackendGenerated
.value) ||
formGroup.controls.externalIdentifierId.value ===
formGroup.controls.externalIdentifierIdStored.value
) {
// do not overwrite the existing URL
} else if (
value.generatedUrl &&
value.generatedUrl !==
formGroup.controls.externalIdentifierUrl.value
) {
formGroup.controls.externalIdentifierUrl.setValue(
decodeURI(value.generatedUrl)
)
formGroup.controls.externalIdentifierUrlWasBackendGenerated.setValue(
decodeURI(value.generatedUrl)
)
} else if (
!value.validFormat ||
(value.attemptedResolution && !value.resolved)
) {
if (!this.work?.putCode) {
formGroup.controls.externalIdentifierUrl.setValue('')
}
}

if (value.attemptedResolution && !value.resolved) {
return {
unResolved: true,
}
if (value.attemptedResolution && !value.resolved) {
return {
unResolved: true,
}
if (!value.validFormat) {
return {
validFormat: true,
}
}
if (!value.validFormat) {
return {
validFormat: true,
}
})
)
}
}
})
)
}
}

Expand Down

0 comments on commit a1c01bc

Please sign in to comment.