Skip to content

Commit

Permalink
Merge pull request #130 from atlp-rwanda/feat-add-notification-sound
Browse files Browse the repository at this point in the history
fix-coupon-usage
  • Loading branch information
faid-terence authored Jul 26, 2024
2 parents 0c47865 + 2f57a31 commit 32b8a73
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/services/couponServices/buyerApplyCoupon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export const buyerApplyCouponService = async (req: Request, res: Response) => {
if (coupon.usageTimes == coupon.maxUsageLimit) {
return res.status(400).json({ message: 'Coupon Discount Ended' });
}

if (req.user?.id) {
if (coupon.usedBy.includes(req.user.id)) {
return res.status(400).json({ message: 'You already used this coupon discount' });
}
}
}
const couponProductId = coupon.product.id;

Expand Down Expand Up @@ -79,22 +85,20 @@ export const buyerApplyCouponService = async (req: Request, res: Response) => {
await sendNotification({
content: `Coupon Code successfully activated discount on product: ${couponCartItem.product.name}`,
type: 'coupon',
user: cart.user
})
user: cart.user,
});

await sendNotification({
content: `Buyer: "${cart?.user.firstName} ${cart?.user.lastName}" used coupon and got discount on product: "${couponCartItem.product.name}"`,
type:'coupon',
user: coupon.vendor
type: 'coupon',
user: coupon.vendor,
});

return res
.status(200)
.json({
message: `Coupon Code successfully activated discount on product: ${couponCartItem.product.name}`,
amountDiscounted: amountReducted,
});
return res.status(200).json({
message: `Coupon Code successfully activated discount on product: ${couponCartItem.product.name}`,
amountDiscounted: amountReducted,
});
} catch (error) {
return responseError(res, 500, (error as Error).message);
}
return responseError(res, 500, (error as Error).message);
}
};

0 comments on commit 32b8a73

Please sign in to comment.