Skip to content

Commit 1a0f82e

Browse files
committed
Fixed small bug
1 parent 678948e commit 1a0f82e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/api/v2/vouchers/route.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ export async function POST(req) {
114114

115115
const amount = params.amount;
116116

117-
const success = await prisma.$transaction(async transaction => {
117+
const error = await prisma.$transaction(async transaction => {
118118
const voucherIds = (await transaction.Voucher.findMany({
119119
select: {
120120
id: true
@@ -132,6 +132,10 @@ export async function POST(req) {
132132
take: amount
133133
})).map(voucher => voucher.id)
134134

135+
if (voucherIds.length != amount) {
136+
return "Not enough vouchers"
137+
}
138+
135139
await transaction.Voucher.updateMany({
136140
where: {
137141
id: {
@@ -162,9 +166,11 @@ export async function POST(req) {
162166
})
163167

164168

165-
return true
169+
return null; // No error in transaction
166170
})
167171

168-
if (success)
172+
if (!error)
169173
return authCheck.verify(NextResponse.json({ status: 200, amount: amount, description: params.description }, { status: 200 }))
174+
else
175+
return authCheck.verify(NextResponse.json({ status: 400, error: error }, { status: 400 }))
170176
}

0 commit comments

Comments
 (0)