Merge pull request #561 from Ayush0730/develop

fix: make packages/medusa/src/services/totals.js pass eslint
This commit is contained in:
Sebastian Rindom
2021-10-20 08:58:55 +02:00
committed by GitHub
2 changed files with 17 additions and 18 deletions
-2
View File
@@ -15,8 +15,6 @@
/packages/medusa/src/services/shipping-profile.js
/packages/medusa/src/services/store.js
/packages/medusa/src/services/swap.js
/packages/medusa/src/services/totals.js
/packages/medusa/src/subscribers/notification.js
/packages/medusa/src/subscribers/order.js
/packages/medusa/src/subscribers/product.js
+17 -16
View File
@@ -5,7 +5,7 @@ import carts from "../api/routes/store/carts"
/**
* A service that calculates total and subtotals for orders, carts etc..
* @implements BaseService
* @implements {BaseService}
*/
class TotalsService extends BaseService {
constructor() {
@@ -49,7 +49,8 @@ class TotalsService extends BaseService {
/**
* Calculates subtotal of a given cart or order.
* @param {Cart || Order} object - cart or order to calculate subtotal for
* @param {(Cart|Order)} object - cart or order to calculate subtotal for
* @param {Object} opts - options
* @return {int} the calculated subtotal
*/
getSubtotal(object, opts = {}) {
@@ -58,7 +59,7 @@ class TotalsService extends BaseService {
return subtotal
}
object.items.map(item => {
object.items.map((item) => {
if (opts.excludeNonDiscounts) {
if (item.allow_discounts) {
subtotal += item.unit_price * item.quantity
@@ -129,7 +130,7 @@ class TotalsService extends BaseService {
const lineDiscounts = this.getLineDiscounts(object, discount)
const discountedLine = lineDiscounts.find(
line => line.item.id === lineItem.id
(line) => line.item.id === lineItem.id
)
const discountAmount =
@@ -149,12 +150,12 @@ class TotalsService extends BaseService {
* @return {int} the calculated subtotal
*/
getRefundTotal(order, lineItems) {
let itemIds = order.items.map(i => i.id)
let itemIds = order.items.map((i) => i.id)
// in case we swap a swap, we need to include swap items
if (order.swaps && order.swaps.length) {
for (const s of order.swaps) {
const swapItemIds = s.additional_items.map(el => el.id)
const swapItemIds = s.additional_items.map((el) => el.id)
itemIds = [...itemIds, ...swapItemIds]
}
}
@@ -185,7 +186,7 @@ class TotalsService extends BaseService {
* @param {string} lineItem - id of line item
* @param {string} variant - id of variant in line item
* @param {int} variantPrice - price of the variant based on region
* @param {int} valye - discount value
* @param {int} value - discount value
* @param {string} discountType - the type of discount (fixed or percentage)
* @return {{ string, string, int }} triples of lineitem, variant and
* applied discount
@@ -279,7 +280,7 @@ class TotalsService extends BaseService {
percentage = nominator / subtotal
}
return merged.map(item => {
return merged.map((item) => {
const lineTotal = item.unit_price * item.quantity
return {
@@ -293,18 +294,18 @@ class TotalsService extends BaseService {
cart,
type
)
return merged.map(item => {
return merged.map((item) => {
const discounted = allocationDiscounts.find(
a => a.lineItem.id === item.id
(a) => a.lineItem.id === item.id
)
return {
item,
amount: !!discounted ? discounted.amount : 0,
amount: discounted ? discounted.amount : 0,
}
})
}
return merged.map(i => ({ item: i, amount: 0 }))
return merged.map((i) => ({ item: i, amount: 0 }))
}
getGiftCardTotal(cart) {
@@ -331,11 +332,11 @@ class TotalsService extends BaseService {
/**
* Calculates the total discount amount for each of the different supported
* discount types. If discounts aren't present or invalid returns 0.
* @param {Cart} Cart - the cart to calculate discounts for
* @param {Cart} cart - the cart to calculate discounts for
* @return {int} the total discounts amount
*/
getDiscountTotal(cart) {
let subtotal = this.getSubtotal(cart, { excludeNonDiscounts: true })
const subtotal = this.getSubtotal(cart, { excludeNonDiscounts: true })
if (!cart.discounts || !cart.discounts.length) {
return 0
@@ -362,7 +363,7 @@ class TotalsService extends BaseService {
cart,
"percentage"
)
toReturn = _.sumBy(itemPercentageDiscounts, d => d.amount)
toReturn = _.sumBy(itemPercentageDiscounts, (d) => d.amount)
} else if (type === "fixed" && allocation === "total") {
toReturn = value
} else if (type === "fixed" && allocation === "item") {
@@ -371,7 +372,7 @@ class TotalsService extends BaseService {
cart,
"fixed"
)
toReturn = _.sumBy(itemFixedDiscounts, d => d.amount)
toReturn = _.sumBy(itemFixedDiscounts, (d) => d.amount)
}
if (subtotal < 0) {