File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed
(pages)/(main)/volunteering/logs Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -151,14 +151,14 @@ function validateVoucherLogRequest(
151151 // Define an object to store the errors
152152 const errors = {
153153 numVouchersError : voucherAmount - numVouchersToUse < 0 || numVouchersToUse <= 0 ,
154- descriptionVoucherError : descriptionVoucher . length === 0 ,
154+ descriptionVoucherError : descriptionVoucher . length === 0 || descriptionVoucher . length > 120 ,
155155 } ;
156156
157157 // Update the error states using the setters
158158 if ( errors . numVouchersError )
159159 setErrorMessage ( numVouchersToUse <= 0 ? "You must have more than one voucher" : "Not enough vouchers" )
160160 if ( errors . descriptionVoucherError )
161- setDescErrorMessage ( " Please describe the purchase" )
161+ setDescErrorMessage ( ` Please describe the purchase (1-120 characters. You had ${ descriptionVoucher . length } )` )
162162 setNumVouchersError ( errors . numVouchersError ) ;
163163 setDescriptionVoucherError ( errors . descriptionVoucherError ) ;
164164
Original file line number Diff line number Diff line change @@ -114,6 +114,14 @@ export async function POST(req) {
114114
115115 const amount = params . amount ;
116116
117+ const desc = params . description ;
118+
119+ if ( ! desc )
120+ return authCheck . verify ( NextResponse . json ( { status : 400 , error : "Missing description" } , { status : 400 } ) )
121+
122+ if ( desc . length === 0 || desc . length > 120 )
123+ return authCheck . verify ( NextResponse . json ( { status : 400 , error : "Invalid description length " + desc . length } , { status : 400 } ) )
124+
117125 const error = await prisma . $transaction ( async transaction => {
118126 const voucherIds = ( await transaction . Voucher . findMany ( {
119127 select : {
You can’t perform that action at this time.
0 commit comments