Skip to content

Commit

Permalink
feat: additional validity check for opportunity type in form
Browse files Browse the repository at this point in the history
Co-authored-by: IlliaDerevianko <[email protected]>
  • Loading branch information
nick-bolas and IlliaDerevianko committed Aug 22, 2024
1 parent 188b910 commit df22a52
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/parsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export const parseString: FormFieldParser<string> = (rawData: FormDataEntryValue

export const parseDateTime: FormFieldParser<Date> = (rawDate: FormDataEntryValue): Date => {
const date = new Date(rawDate.toString().trim())
console.log(rawDate)
// Check if the date is valid
if (isNaN(date.getTime())) {
throw new Error("Parsing error. Invalid datetime format.")
Expand All @@ -34,5 +33,8 @@ export const parseOpportunityType: FormFieldParser<OpportunityType> = (
rawType: FormDataEntryValue,
): OpportunityType => {
const type = parseString(rawType)
if (!Object.keys(OpportunityType).includes(type)) {
throw new Error("Parsing error. The provided type of opportunity does not exist.")
}
return type as OpportunityType
}

0 comments on commit df22a52

Please sign in to comment.