Skip to content

Commit c978174

Browse files
committed
refactor: clean up
1 parent 13e6afe commit c978174

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

utils/validators.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ export interface CreatePaymentIdInput {
590590
fields?: ClientPaymentField[]
591591
}
592592

593-
export const parseClientPaymentFields = function (fieldsInput: string | undefined): ClientPaymentField[] | undefined {
593+
export const parseClientPaymentFields = function (fieldsInput: string | object | undefined): ClientPaymentField[] | undefined {
594594
if (fieldsInput === undefined || fieldsInput === '') {
595595
return undefined
596596
}
@@ -617,12 +617,14 @@ export const parseClientPaymentFields = function (fieldsInput: string | undefine
617617
typeof field.name !== 'string' ||
618618
field.name?.trim() === ''
619619
) {
620-
console.log('field:', field)
621620
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
622621
}
623622
if (field.value !== undefined && typeof field.value !== 'string' && typeof field.value !== 'boolean') {
624623
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
625624
}
625+
if (field.type !== undefined && typeof field.type !== 'string') {
626+
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
627+
}
626628
if (field.text !== undefined && typeof field.text !== 'string') {
627629
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
628630
}
@@ -639,7 +641,7 @@ export const parseAmount = function (amountInput: string | undefined): Prisma.De
639641
const trimmedAmount = amountInput.trim()
640642
const numericAmount = Number(trimmedAmount)
641643

642-
if (isNaN(numericAmount) || numericAmount <= 0) {
644+
if (isNaN(numericAmount) || !isFinite(numericAmount) || numericAmount <= 0) {
643645
throw new Error(RESPONSE_MESSAGES.INVALID_AMOUNT_400.message)
644646
}
645647

0 commit comments

Comments
 (0)