Skip to content

Commit

Permalink
Made code reviews and fixed an existing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
mamartinezmejia committed Dec 12, 2023
1 parent 4dc35c0 commit 489409a
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions frontend/src/helpers/validators/GlobalValidators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,14 +288,14 @@ export const isWithinRange =
/**
* Checks if the value is a possibly valid day for the specified month.
* Note: February 29 will always be considered valid, since this validation does not consider the year.
*
*
* @param validMonth a valid month
* @param message the error message to be returned if the validation fails.
*/
export const isValidDayOfMonth =
(
validMonth: string,
message = "Value is not a valid day in the selected month",
message = "Value is not a valid day in the selected month"
) =>
(value: string): string => {
const arbitraryLeapYear = 2000;
Expand All @@ -310,7 +310,7 @@ export const isValidDayOfMonth =
/**
* Checks if the value is a valid day for the specified year and month.
* i.e. it tells if the date formed by the provided year, month and day exists.
*
*
* @param validYear a valid year
* @param validMonth a valid month
* @param message the error message to be returned if the validation fails.
Expand All @@ -319,7 +319,7 @@ export const isValidDayOfMonthYear =
(
validYear: string,
validMonth: string,
message = "Value is not a valid day in the selected month and year",
message = "Value is not a valid day in the selected month and year"
) =>
(value: string): string => {
const dateString = `${validYear}-${validMonth}-${value}`;
Expand All @@ -334,7 +334,7 @@ export const isMinimumYearsAgo =
(
years: number,
message: string | ((years: number) => string) = (years) =>
`Value must be at least ${years} years ago`,
`Value must be at least ${years} years ago`
) =>
(value: string): string => {
const maximumDate = subYears(startOfToday(), years);
Expand All @@ -349,7 +349,10 @@ export const isMinimumYearsAgo =
};

export const isGreaterThan =
(compareTo: number, message: string = `Value must be greater than ${compareTo}`) =>
(
compareTo: number,
message: string = `Value must be greater than ${compareTo}`
) =>
(value: string): string => {
if (Number(value) > compareTo) {
return "";
Expand All @@ -358,15 +361,18 @@ export const isGreaterThan =
};

export const isLessThan =
(compareTo: number, message: string = `Value must be less than ${compareTo}`) =>
(
compareTo: number,
message: string = `Value must be less than ${compareTo}`
) =>
(value: string): string => {
if (Number(value) < compareTo) {
return "";
}
return message;
};

export const isDateInThePast = (message: "Value must be in the past") => (value: string) => {
export const isDateInThePast = (message: string) => (value: string) => {
const dateValue = parseISO(value);
if (!isBefore(dateValue, startOfToday())) {
return message;
Expand Down Expand Up @@ -447,7 +453,8 @@ export const validate = (
condition: string,
fieldId: string = fieldKey
): string => {
if (eval(condition)) { // NOSONAR
if (eval(condition)) {
// NOSONAR
const validationResponse = validation(item);
if (notify && validationResponse) {
errorBus.emit([{ fieldId, errorMsg: validationResponse }]);
Expand Down Expand Up @@ -519,7 +526,8 @@ export const runValidation = (
condition: string,
fieldId: string = fieldKey
): string => {
if (eval(condition)) { // NOSONAR
if (eval(condition)) {
// NOSONAR
const validationResponse = validation(item);
if (notify) {
// Note: also notifies when valid - errorMsg will be empty.
Expand Down

0 comments on commit 489409a

Please sign in to comment.