fix: prettier
This commit is contained in:
@@ -160,7 +160,7 @@ class CartService extends BaseService {
|
||||
"total",
|
||||
]
|
||||
|
||||
const totalsToSelect = select.filter((v) => totalFields.includes(v))
|
||||
const totalsToSelect = select.filter(v => totalFields.includes(v))
|
||||
if (totalsToSelect.length > 0) {
|
||||
const relationSet = new Set(relations)
|
||||
relationSet.add("items")
|
||||
@@ -173,7 +173,7 @@ class CartService extends BaseService {
|
||||
relationSet.add("region")
|
||||
relations = [...relationSet]
|
||||
|
||||
select = select.filter((v) => !totalFields.includes(v))
|
||||
select = select.filter(v => !totalFields.includes(v))
|
||||
}
|
||||
|
||||
return {
|
||||
@@ -273,7 +273,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise} the result of the create operation
|
||||
*/
|
||||
async create(data) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
const addressRepo = manager.getCustomRepository(this.addressRepository_)
|
||||
const { region_id } = data
|
||||
@@ -342,7 +342,7 @@ class CartService extends BaseService {
|
||||
* @retur {Promise} the result of the update operation
|
||||
*/
|
||||
async removeLineItem(cartId, lineItemId) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: [
|
||||
"items",
|
||||
@@ -352,7 +352,7 @@ class CartService extends BaseService {
|
||||
],
|
||||
})
|
||||
|
||||
const lineItem = cart.items.find((li) => li.id === lineItemId)
|
||||
const lineItem = cart.items.find(li => li.id === lineItemId)
|
||||
if (!lineItem) {
|
||||
return cart
|
||||
}
|
||||
@@ -421,7 +421,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise} the result of the update operation
|
||||
*/
|
||||
async addLineItem(cartId, lineItem) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: [
|
||||
"shipping_methods",
|
||||
@@ -434,7 +434,7 @@ class CartService extends BaseService {
|
||||
|
||||
let currentItem
|
||||
if (lineItem.should_merge) {
|
||||
currentItem = cart.items.find((line) => {
|
||||
currentItem = cart.items.find(line => {
|
||||
if (line.should_merge && line.variant_id === lineItem.variant_id) {
|
||||
return _.isEqual(line.metadata, lineItem.metadata)
|
||||
}
|
||||
@@ -500,13 +500,13 @@ class CartService extends BaseService {
|
||||
* @return {Promise} the result of the update operation
|
||||
*/
|
||||
async updateLineItem(cartId, lineItemId, lineItemUpdate) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["items", "payment_sessions"],
|
||||
})
|
||||
|
||||
// Ensure that the line item exists in the cart
|
||||
const lineItemExists = cart.items.find((i) => i.id === lineItemId)
|
||||
const lineItemExists = cart.items.find(i => i.id === lineItemId)
|
||||
if (!lineItemExists) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
@@ -553,7 +553,7 @@ class CartService extends BaseService {
|
||||
// if any free shipping discounts, we ensure to update shipping method amount
|
||||
if (shouldAdd) {
|
||||
await Promise.all(
|
||||
cart.shipping_methods.map(async (sm) => {
|
||||
cart.shipping_methods.map(async sm => {
|
||||
const smRepo = this.manager_.getCustomRepository(
|
||||
this.shippingMethodRepository_
|
||||
)
|
||||
@@ -568,7 +568,7 @@ class CartService extends BaseService {
|
||||
)
|
||||
} else {
|
||||
await Promise.all(
|
||||
cart.shipping_methods.map(async (sm) => {
|
||||
cart.shipping_methods.map(async sm => {
|
||||
const smRepo = this.manager_.getCustomRepository(
|
||||
this.shippingMethodRepository_
|
||||
)
|
||||
@@ -584,7 +584,7 @@ class CartService extends BaseService {
|
||||
}
|
||||
|
||||
async update(cartId, update) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
const cart = await this.retrieve(cartId, {
|
||||
select: [
|
||||
@@ -938,7 +938,7 @@ class CartService extends BaseService {
|
||||
const toParse = [...cart.discounts, discount]
|
||||
|
||||
let sawNotShipping = false
|
||||
const newDiscounts = toParse.map((d) => {
|
||||
const newDiscounts = toParse.map(d => {
|
||||
const drule = d.rule
|
||||
switch (drule.type) {
|
||||
case "free_shipping":
|
||||
@@ -968,7 +968,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise<Cart>} the resulting cart
|
||||
*/
|
||||
async removeDiscount(cartId, discountCode) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["discounts", "payment_sessions", "shipping_methods"],
|
||||
})
|
||||
@@ -977,7 +977,7 @@ class CartService extends BaseService {
|
||||
await this.adjustFreeShipping_(cart, false)
|
||||
}
|
||||
|
||||
cart.discounts = cart.discounts.filter((d) => d.code !== discountCode)
|
||||
cart.discounts = cart.discounts.filter(d => d.code !== discountCode)
|
||||
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
|
||||
@@ -1008,7 +1008,7 @@ class CartService extends BaseService {
|
||||
* Updates the currently selected payment session.
|
||||
*/
|
||||
async updatePaymentSession(cartId, update) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["payment_sessions"],
|
||||
})
|
||||
@@ -1042,7 +1042,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise<Cart>} the resulting cart
|
||||
*/
|
||||
async authorizePayment(cartId, context = {}) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cartRepository = manager.getCustomRepository(this.cartRepository_)
|
||||
|
||||
const cart = await this.retrieve(cartId, {
|
||||
@@ -1089,7 +1089,7 @@ class CartService extends BaseService {
|
||||
* @returns {Promise} result of update operation
|
||||
*/
|
||||
async setPaymentSession(cartId, providerId) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const psRepo = manager.getCustomRepository(this.paymentSessionRepository_)
|
||||
|
||||
const cart = await this.retrieve(cartId, {
|
||||
@@ -1118,13 +1118,13 @@ class CartService extends BaseService {
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
cart.payment_sessions.map((ps) => {
|
||||
cart.payment_sessions.map(ps => {
|
||||
return psRepo.save({ ...ps, is_selected: null })
|
||||
})
|
||||
)
|
||||
|
||||
const sess = cart.payment_sessions.find(
|
||||
(ps) => ps.provider_id === providerId
|
||||
ps => ps.provider_id === providerId
|
||||
)
|
||||
|
||||
sess.is_selected = true
|
||||
@@ -1150,7 +1150,7 @@ class CartService extends BaseService {
|
||||
* @returns {Promise} the result of the update operation.
|
||||
*/
|
||||
async setPaymentSessions(cartOrCartId) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const psRepo = manager.getCustomRepository(this.paymentSessionRepository_)
|
||||
|
||||
let cartId =
|
||||
@@ -1233,7 +1233,7 @@ class CartService extends BaseService {
|
||||
* @returns {Promise<Cart>} the resulting cart.
|
||||
*/
|
||||
async deletePaymentSession(cartId, providerId) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["payment_sessions"],
|
||||
})
|
||||
@@ -1274,7 +1274,7 @@ class CartService extends BaseService {
|
||||
* @returns {Promise<Cart>} the resulting cart.
|
||||
*/
|
||||
async refreshPaymentSession(cartId, providerId) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["payment_sessions"],
|
||||
})
|
||||
@@ -1313,7 +1313,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise} the result of the update operation
|
||||
*/
|
||||
async addShippingMethod(cartId, optionId, data) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
select: ["subtotal"],
|
||||
relations: [
|
||||
@@ -1397,7 +1397,7 @@ class CartService extends BaseService {
|
||||
if (cart.items.length) {
|
||||
cart.items = await Promise.all(
|
||||
cart.items
|
||||
.map(async (item) => {
|
||||
.map(async item => {
|
||||
const availablePrice = await this.productVariantService_
|
||||
.getRegionPrice(item.variant_id, regionId)
|
||||
.catch(() => undefined)
|
||||
@@ -1476,20 +1476,20 @@ class CartService extends BaseService {
|
||||
}
|
||||
|
||||
if (cart.discounts && cart.discounts.length) {
|
||||
const newDiscounts = cart.discounts.map((d) => {
|
||||
const newDiscounts = cart.discounts.map(d => {
|
||||
if (d.regions.find(({ id }) => id === regionId)) {
|
||||
return d
|
||||
}
|
||||
})
|
||||
|
||||
cart.discounts = newDiscounts.filter((d) => !!d)
|
||||
cart.discounts = newDiscounts.filter(d => !!d)
|
||||
}
|
||||
|
||||
cart.gift_cards = []
|
||||
|
||||
if (cart.payment_sessions && cart.payment_sessions.length) {
|
||||
await Promise.all(
|
||||
cart.payment_sessions.map((ps) =>
|
||||
cart.payment_sessions.map(ps =>
|
||||
this.paymentProviderService_
|
||||
.withTransaction(this.manager_)
|
||||
.deleteSession(ps)
|
||||
@@ -1507,7 +1507,7 @@ class CartService extends BaseService {
|
||||
* not found.
|
||||
*/
|
||||
async delete(cartId) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cart = await this.retrieve(cartId, {
|
||||
relations: ["items", "discounts", "payment_sessions"],
|
||||
})
|
||||
@@ -1541,7 +1541,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise} resolves to the updated result.
|
||||
*/
|
||||
async setMetadata(cartId, key, value) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
|
||||
const validatedId = this.validateId_(cartId)
|
||||
@@ -1575,7 +1575,7 @@ class CartService extends BaseService {
|
||||
* @return {Promise} resolves to the updated result.
|
||||
*/
|
||||
async deleteMetadata(cartId, key) {
|
||||
return this.atomicPhase_(async (manager) => {
|
||||
return this.atomicPhase_(async manager => {
|
||||
const cartRepo = manager.getCustomRepository(this.cartRepository_)
|
||||
const validatedId = this.validateId_(cartId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user