Skip to content

Commit

Permalink
ignore coupon limit checks (#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
rajranjan0608 authored Jul 22, 2024
1 parent 3eec805 commit 62862dc
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions CouponService/couponService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ type CouponConfig = {
MAX_LIMIT_CAP: number,
}

function validateCouponData(coupon: any, couponConfig: CouponConfig): Coupon | undefined {
function validateCouponData(coupon: any, couponConfig: CouponConfig, ignoreCouponLimitCheck = true): Coupon | undefined {
if (
coupon.id &&
coupon.faucetConfigId &&
coupon.maxLimitAmount > 0 &&
coupon.maxLimitAmount <= couponConfig.MAX_LIMIT_CAP &&
(ignoreCouponLimitCheck || coupon.maxLimitAmount <= couponConfig.MAX_LIMIT_CAP) &&
coupon.consumedAmount <= coupon.maxLimitAmount &&
coupon.expiry > 0
) {
Expand Down Expand Up @@ -77,7 +77,7 @@ export class CouponService {

// Fetches new coupons from database into memory
result?.Items?.forEach((item: Record<string, any>) => {
const coupon: Coupon | undefined = validateCouponData(item, this.couponConfig)
const coupon: Coupon | undefined = validateCouponData(item, this.couponConfig, true)
if (coupon) {
dbItemSet.add(coupon.id)

Expand Down Expand Up @@ -114,9 +114,10 @@ export class CouponService {
Key: {
id: couponItem.id,
},
UpdateExpression: 'SET consumedAmount = :consumedAmount',
UpdateExpression: 'SET consumedAmount = :consumedAmount, reset = :reset',
ExpressionAttributeValues: {
':consumedAmount': couponItem.consumedAmount,
':reset': couponItem.reset ?? false,
},
}

Expand Down

0 comments on commit 62862dc

Please sign in to comment.