Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(couponsBelowLimit.length && params.payment_type == 1) {
  2.                 let wrWithDiscount = couponsBelowLimit.map(c => {
  3.  
  4.                     let discount
  5.  
  6.                     if(c.discount_percentage) {
  7.                         discount = (wr.price - (wr.price * c.discount_percentage / 100))
  8.                     }
  9.  
  10.                     if(c.discount_price) {
  11.                         discount = (wr.price - c.discount_price)
  12.                     }
  13.  
  14.                     return {
  15.                         coupon_id: c.id,
  16.                         discount: discount
  17.                     }
  18.                 })
  19.                
  20.                 console.log('Desconto:', wrWithDiscount)
  21.  
  22.                 let smallest = wrWithDiscount.reduce((a, b) => (a.discount > b.discount) ? a : b)
  23.                 wr.price = smallest.discount.toFixed(2)
  24.  
  25.                 yield WashingRequest.query().update({price: smallest.discount, coupon_id: smallest.coupon_id})
  26.                         .where('id', params.washing_request_id)
  27.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement