Untitled
unknown
javascript
21 days ago
743 B
4
Indexable
Never
function generateCouponCode(productCode, discountAmount) { const randomString = Math.random().toString(36).substring(2, 8).toUpperCase(); return `COUPON-${productCode}-${discountAmount}-${randomString}`; } // Endpoint to generate a coupon code app.post('/generate-coupon', (req, res) => { const { productCode, discountAmount } = req.body; // Validate discount amount if (discountAmount < 100 || discountAmount > 500) { return res.status(400).json({ message: 'Discount amount must be between 100 and 500 taka' }); } // Generate coupon code const couponCode = generateCouponCode(productCode, discountAmount); // Respond with the generated coupon code res.status(200).json({ couponCode }); });
Leave a Comment