From 23e83aff1cd858401fba42668f641270128068e1 Mon Sep 17 00:00:00 2001 From: Ayush Jain Date: Thu, 14 Oct 2021 17:57:54 +0530 Subject: [PATCH] fix: make packages/medusa/src/services/totals.js pass eslint --- .eslintignore | 1 - packages/medusa/src/services/totals.js | 35 +++++++++++++------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.eslintignore b/.eslintignore index 1faf09169d..fe0209a199 100644 --- a/.eslintignore +++ b/.eslintignore @@ -25,7 +25,6 @@ /packages/medusa/src/services/store.js /packages/medusa/src/services/swap.js /packages/medusa/src/services/system-payment-provider.js -/packages/medusa/src/services/totals.js /packages/medusa/src/subscribers/notification.js /packages/medusa/src/subscribers/order.js diff --git a/packages/medusa/src/services/totals.js b/packages/medusa/src/services/totals.js index 7802999585..c50a4b7d1d 100644 --- a/packages/medusa/src/services/totals.js +++ b/packages/medusa/src/services/totals.js @@ -4,7 +4,7 @@ import { MedusaError } from "medusa-core-utils" /** * A service that calculates total and subtotals for orders, carts etc.. - * @implements BaseService + * @implements {BaseService} */ class TotalsService extends BaseService { constructor() { @@ -48,7 +48,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 = {}) { @@ -57,7 +58,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 @@ -128,7 +129,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 = @@ -148,17 +149,17 @@ 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] } } - const refunds = lineItems.map(i => { + const refunds = lineItems.map((i) => { if (!itemIds.includes(i.id)) { throw new MedusaError( MedusaError.Types.INVALID_DATA, @@ -177,7 +178,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 @@ -265,7 +266,7 @@ class TotalsService extends BaseService { percentage = nominator / subtotal } - return merged.map(item => { + return merged.map((item) => { const lineTotal = item.unit_price * item.quantity return { @@ -279,18 +280,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) { @@ -317,11 +318,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 @@ -348,7 +349,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") { @@ -357,7 +358,7 @@ class TotalsService extends BaseService { cart, "fixed" ) - toReturn = _.sumBy(itemFixedDiscounts, d => d.amount) + toReturn = _.sumBy(itemFixedDiscounts, (d) => d.amount) } if (subtotal < 0) {