Skip to content

Commit 4798a66

Browse files
committed
Fixed description length issue. Transaction would fail if description was longer than 120 chars
1 parent 633c750 commit 4798a66

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

app/(pages)/(main)/volunteering/logs/voucherLogInput.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

app/api/v2/vouchers/route.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff 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: {

0 commit comments

Comments
 (0)