-
Notifications
You must be signed in to change notification settings - Fork 14
#2033 - Validating FT and PT offering minimum length #2041
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
dheepak-aot
merged 6 commits into
main
from
enhancement/#2033-minimum-study-period-length
Jun 27, 2023
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
05174b8
validating the offering minimum length for fulltime and parttime sepe…
dheepak-aot e00da1f
validating the offering minimum length for fulltime and parttime sepe…
dheepak-aot 49128ee
form definition update with client variables
dheepak-aot e9d379d
Fixing comments
dheepak-aot c84a399
review comments
dheepak-aot 346455b
review comments
dheepak-aot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,23 +15,38 @@ import { dateDifference, getDateOnlyFormat } from "@sims/utilities"; | |
@ValidatorConstraint() | ||
class PeriodMinLengthConstraint implements ValidatorConstraintInterface { | ||
validate(value: Date | string, args: ValidationArguments): boolean { | ||
const [startDateProperty, minDaysAllowed] = args.constraints; | ||
const [startDateProperty] = args.constraints; | ||
const minDaysAllowedValue = this.getMinAllowedDays(args); | ||
const periodStartDate = startDateProperty(args.object); | ||
if (!periodStartDate) { | ||
// The related property does not exists in the provided object to be compared. | ||
return false; | ||
} | ||
return dateDifference(value, periodStartDate) >= minDaysAllowed; | ||
return dateDifference(value, periodStartDate) >= minDaysAllowedValue; | ||
} | ||
|
||
defaultMessage(args: ValidationArguments) { | ||
const [startDateProperty, minDaysAllowed, propertyDisplayName] = | ||
args.constraints; | ||
const [startDateProperty, , propertyDisplayName] = args.constraints; | ||
const startDate = getDateOnlyFormat(startDateProperty(args.object)); | ||
const endDate = getDateOnlyFormat(args.value); | ||
const minDaysAllowedValue = this.getMinAllowedDays(args); | ||
return `${ | ||
propertyDisplayName ?? args.property | ||
}, the number of day(s) between ${startDate} and ${endDate} must be at least ${minDaysAllowed}.`; | ||
}, the number of day(s) between ${startDate} and ${endDate} must be at least ${minDaysAllowedValue}.`; | ||
} | ||
|
||
/** | ||
* Get minimum allowed days from args. | ||
* @param args validation arguments. | ||
* @returns minimum allowed days. | ||
*/ | ||
private getMinAllowedDays(args: ValidationArguments): number { | ||
const [, minDaysAllowed] = args.constraints; | ||
const minDaysAllowedValue = | ||
minDaysAllowed instanceof Function | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool! |
||
? (minDaysAllowed(args.object) as number) | ||
andrewsignori-aot marked this conversation as resolved.
Show resolved
Hide resolved
|
||
: minDaysAllowed; | ||
return minDaysAllowedValue as number; | ||
} | ||
} | ||
|
||
|
@@ -42,14 +57,15 @@ class PeriodMinLengthConstraint implements ValidatorConstraintInterface { | |
* @param startDateProperty indicates the property that define the | ||
* start of a period. | ||
* @param minDaysAllowed min allowed days to the period be considered valid. | ||
* This could be a number or a function that returns a value of minimum allowed days. | ||
* @param propertyDisplayName user-friendly property name to be added to the | ||
* validation message. | ||
* @param validationOptions validations options. | ||
* @returns true if the period amount of days is inside the min allowed days. | ||
*/ | ||
export function PeriodMinLength( | ||
startDateProperty: (targetObject: unknown) => Date | string, | ||
minDaysAllowed: number, | ||
minDaysAllowed: ((targetObject: unknown) => number) | number, | ||
propertyDisplayName?: string, | ||
validationOptions?: ValidationOptions, | ||
) { | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice implementation to pass the args from the form with respect to the offering intensity, but can this be shared done as a constant without passing them from the form?