Skip to content

Commit

Permalink
Merge pull request #80 from HackRU/points-fix
Browse files Browse the repository at this point in the history
To deny event attendance to negative balances
  • Loading branch information
ethxng authored Oct 20, 2024
2 parents fa6b1e0 + 98031fe commit a67a388
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/functions/attend-event/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,19 @@ const attendEvent: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (ev
});
}

if (event.body.points < 0 && userPoints.balance + event.body.points < 0) {
return {
statusCode: 409,
body: JSON.stringify({
statusCode: 409,
message: 'User does not have enough points to check into event.',
balance: userPoints.balance,
}),
};
}

if (event.body.points < 0)
// note: the operation is $inc but since points is negative, it will still subtract
await points.updateOne({ email: event.body.qr }, { $inc: { balance: event.body.points } });
else if (event.body.points > 0) {
await points.updateOne(
Expand Down

0 comments on commit a67a388

Please sign in to comment.