-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(fa): Fixing error messages in financial-aid (#15589)
* adding sortable feature * Revert "adding sortable feature" This reverts commit d9691c5. * adding more detail for api * removing white space break just adding html element to the db * adding children to api * checing if municpality code or api key are valid * adding error message if header info is missing * fixing error * adding date check * code rabbit fix * moving logic to guard instead of controller * chaning to string that allows two possibilities * fixing linting
- Loading branch information
1 parent
9020fbf
commit 390aa85
Showing
5 changed files
with
92 additions
and
8 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,39 @@ | ||
import { BadRequestException } from '@nestjs/common' | ||
|
||
export const isDateValid = ( | ||
startDate: string, | ||
dateType: 'endDate' | 'startDate', | ||
): boolean => { | ||
// Regular expression to match the YYYY-MM-DD format | ||
const regex = /^\d{4}-\d{2}-\d{2}$/ | ||
if (!regex.test(startDate)) { | ||
throw new BadRequestException( | ||
`${dateType} is not formatted correctly, should be year-month-date e.g. 2024-02-22`, | ||
) | ||
} | ||
|
||
// Parse the input string into a Date object | ||
const date = new Date(startDate) | ||
const isValidDate = date instanceof Date && !Number.isNaN(date.getTime()) | ||
const [year, month, day] = startDate.split('-').map(Number) | ||
const isCorrectDate = | ||
date.getFullYear() === year && | ||
date.getMonth() + 1 === month && | ||
date.getDate() === day | ||
|
||
if (!isValidDate || !isCorrectDate) { | ||
throw new BadRequestException(`${dateType} is not valid`) | ||
} | ||
|
||
// Get the current date without the time portion | ||
const today = new Date() | ||
today.setHours(0, 0, 0, 0) | ||
|
||
// Check that the date is not in the future | ||
const isNotInFuture = date <= today | ||
if (!isNotInFuture) { | ||
throw new BadRequestException(`${dateType} cannot be in the future`) | ||
} | ||
|
||
return true | ||
} |