forked from bloom-housing/bloom
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add backend url validation for url fields (bloom-housing#3568)
* fix: add backend url validation for url fields * fix: validate only if externalUrl should be URL * fix: use form values for application types on failed form submit * fix: hide url field when no digital application * fix: set proper default value to common digital application choice * fix: add hasHttps decorator for second error variant
- Loading branch information
1 parent
04b7695
commit 5a348e0
Showing
8 changed files
with
85 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { | ||
registerDecorator, | ||
ValidationArguments, | ||
ValidationOptions, | ||
ValidatorConstraint, | ||
ValidatorConstraintInterface, | ||
} from "class-validator" | ||
|
||
export function hasHttps(validationOptions?: ValidationOptions) { | ||
return function (object: unknown, propertyName: string) { | ||
registerDecorator({ | ||
target: object.constructor, | ||
propertyName, | ||
options: validationOptions, | ||
constraints: [], | ||
validator: hasHttpsConstraint, | ||
}) | ||
} | ||
} | ||
|
||
@ValidatorConstraint({ name: "hasHttps" }) | ||
export class hasHttpsConstraint implements ValidatorConstraintInterface { | ||
validate(url: string) { | ||
const httpsRegex = /^https?:\/\//i | ||
return httpsRegex.test(url) | ||
} | ||
|
||
defaultMessage(args: ValidationArguments) { | ||
return `${args.property} must have https://` | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters