Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(couponsBelowLimit.length && params.payment_type == 1) {
- let wrWithDiscount = couponsBelowLimit.map(c => {
- let discount
- if(c.discount_percentage) {
- discount = (wr.price - (wr.price * c.discount_percentage / 100))
- }
- if(c.discount_price) {
- discount = (wr.price - c.discount_price)
- }
- return {
- coupon_id: c.id,
- discount: discount
- }
- })
- console.log('Desconto:', wrWithDiscount)
- let smallest = wrWithDiscount.reduce((a, b) => (a.discount > b.discount) ? a : b)
- wr.price = smallest.discount.toFixed(2)
- yield WashingRequest.query().update({price: smallest.discount, coupon_id: smallest.coupon_id})
- .where('id', params.washing_request_id)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement