Skip to content

Commit 3f65401

Browse files
committed
\refactor: clean up
1 parent 13e6afe commit 3f65401

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

utils/validators.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -577,20 +577,14 @@ export interface CreatePaymentIdPOSTParameters {
577577
amount?: string
578578
fields?: string
579579
}
580-
export interface ClientPaymentFieldInput {
581-
name?: string
582-
text?: string
583-
type?: string
584-
value?: string | boolean
585-
}
586580

587581
export interface CreatePaymentIdInput {
588582
address: string
589583
amount?: Prisma.Decimal
590584
fields?: ClientPaymentField[]
591585
}
592586

593-
export const parseClientPaymentFields = function (fieldsInput: string | undefined): ClientPaymentField[] | undefined {
587+
export const parseClientPaymentFields = function (fieldsInput: string | object | undefined): ClientPaymentField[] | undefined {
594588
if (fieldsInput === undefined || fieldsInput === '') {
595589
return undefined
596590
}
@@ -617,12 +611,14 @@ export const parseClientPaymentFields = function (fieldsInput: string | undefine
617611
typeof field.name !== 'string' ||
618612
field.name?.trim() === ''
619613
) {
620-
console.log('field:', field)
621614
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
622615
}
623616
if (field.value !== undefined && typeof field.value !== 'string' && typeof field.value !== 'boolean') {
624617
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
625618
}
619+
if (field.type !== undefined && typeof field.type !== 'string') {
620+
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
621+
}
626622
if (field.text !== undefined && typeof field.text !== 'string') {
627623
throw new Error(RESPONSE_MESSAGES.INVALID_FIELD_STRUCTURE_400.message)
628624
}
@@ -639,7 +635,7 @@ export const parseAmount = function (amountInput: string | undefined): Prisma.De
639635
const trimmedAmount = amountInput.trim()
640636
const numericAmount = Number(trimmedAmount)
641637

642-
if (isNaN(numericAmount) || numericAmount <= 0) {
638+
if (isNaN(numericAmount) || !isFinite(numericAmount) || numericAmount <= 0) {
643639
throw new Error(RESPONSE_MESSAGES.INVALID_AMOUNT_400.message)
644640
}
645641

0 commit comments

Comments
 (0)