@@ -9,9 +9,9 @@ const PAYMENT_FORM_LINK_REGEX = /^https:\/\/(staging.)?pay.gov.sg\/forms\/(.*)$/
99
1010export const requestSchema = z . object ( {
1111 formId : z
12- . string ( )
12+ . string ( { invalid_type_error : 'Empty payment form link' } )
1313 . trim ( )
14- . min ( 1 , { message : 'Specify a form link' } )
14+ . min ( 1 , { message : 'Specify a payment form link' } )
1515 . transform ( ( value , context ) => {
1616 const match = value . match ( PAYMENT_FORM_LINK_REGEX )
1717
@@ -26,16 +26,19 @@ export const requestSchema = z.object({
2626 return match [ 2 ]
2727 } ) ,
2828 formsg_form_id : z
29- . string ( )
29+ . string ( { invalid_type_error : 'Empty FormSG form ID' } )
3030 . trim ( )
3131 . length ( FORM_ID_LENGTH , { message : 'Specify a valid FormSG form ID' } ) ,
3232 formsg_submission_id : z
33- . string ( )
33+ . string ( { invalid_type_error : 'Empty FormSG submission ID' } )
3434 . trim ( )
3535 . min ( 1 , { message : 'Specify a submission ID' } ) ,
36- nonce : z . string ( ) . trim ( ) . min ( 1 , { message : 'Specify a nonce field' } ) ,
36+ nonce : z
37+ . string ( { invalid_type_error : 'Empty FormSG reference field answer' } )
38+ . trim ( )
39+ . min ( 1 , { message : 'Specify a FormSG reference field answer' } ) ,
3740 payer_name : z
38- . string ( )
41+ . string ( { invalid_type_error : 'Empty payer name' } )
3942 . trim ( )
4043 . min ( 1 , { message : 'Empty payer name' } )
4144 . max ( 255 , { message : 'Payer name cannot be more than 255 characters' } )
@@ -65,8 +68,10 @@ export const requestSchema = z.object({
6568 . min ( 1 , { message : 'Empty payment amount' } )
6669 . pipe (
6770 z . coerce
68- . number ( )
69- . int ( 'Payment amount must be round number' )
71+ . number ( {
72+ invalid_type_error : 'Payment amount must be a number' ,
73+ } )
74+ . int ( 'Payment amount must be a round number' )
7075 . min ( 50 , { message : 'Payment amount must be larger than 50 cents' } )
7176 . max ( 99999999 , {
7277 message : 'Payment amount cannot be larger than $999999.99' ,
@@ -80,8 +85,14 @@ export const requestSchema = z.object({
8085 . optional ( ) ,
8186 responses : z . array (
8287 z . object ( {
83- question : z . string ( ) . trim ( ) . min ( 1 , { message : 'Empty question' } ) ,
84- answer : z . string ( ) . trim ( ) . min ( 1 , { message : 'Empty answer' } ) ,
88+ question : z
89+ . string ( { invalid_type_error : 'Empty question' } )
90+ . trim ( )
91+ . min ( 1 , { message : 'Empty question' } ) ,
92+ answer : z
93+ . string ( { invalid_type_error : 'Empty answer' } )
94+ . trim ( )
95+ . min ( 1 , { message : 'Empty answer' } ) ,
8596 } ) ,
8697 ) ,
8798} )
0 commit comments