Skip to content

Commit

Permalink
Fix edit asset form validator
Browse files Browse the repository at this point in the history
  • Loading branch information
illfixit authored Oct 4, 2024
1 parent c4562ba commit 1a8585e
Showing 1 changed file with 2 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,15 @@ export class EditAssetFormValidators {
/**
* Use on asset control, reset asset control on publish mode changes, accesses parent form
*/
isValidId(): AsyncValidatorFn {
isValidId(): AsyncValidatorFn {
return (control: AbstractControl): Observable<ValidationErrors | null> => {
const value = control?.parent?.parent?.value as EditAssetFormValue | null;
if (value?.mode !== 'CREATE') {
return of(null);
}

const assetId = control.value! as string;
if (value.publishMode === 'PUBLISH_UNRESTRICTED') {
return combineLatest([
this.assetIdExistsErrorMessage(assetId),
this.contractDefinitionIdErrorMessage(assetId),
this.policyIdExistsErrorMessage(ALWAYS_TRUE_POLICY_ID).pipe(
map((errorMessage) =>
// We want to throw an error if always-true was not found
errorMessage ? null : 'Always True Policy does not exist.',
),
),
]).pipe(
map((errorMessages) => this.buildValidationErrors(errorMessages)),
);
} else if (value.publishMode === 'PUBLISH_RESTRICTED') {
if (value.publishMode !== 'DO_NOT_PUBLISH') {
return combineLatest([
this.assetIdExistsErrorMessage(assetId),
this.contractDefinitionIdErrorMessage(assetId),
Expand All @@ -55,7 +42,6 @@ export class EditAssetFormValidators {
map((result) => this.buildValidationErrors([result])),
);
}

return of(null);
};
}
Expand Down

0 comments on commit 1a8585e

Please sign in to comment.