fix/chore: Make packages/medusa/src/services/store.js pass linting #526 (#601)

This commit is contained in:
saurabh042
2021-10-25 00:03:44 +05:30
committed by GitHub
parent 5fbce42948
commit 82eee77610
2 changed files with 14 additions and 18 deletions

View File

@@ -8,7 +8,6 @@
/packages/medusa/src/services/product-variant.js
/packages/medusa/src/services/product.js
/packages/medusa/src/services/shipping-profile.js
/packages/medusa/src/services/store.js
/packages/medusa/src/subscribers/notification.js
/packages/medusa/src/subscribers/order.js
/packages/medusa/src/subscribers/product.js

View File

@@ -1,12 +1,11 @@
import _ from "lodash"
import { Validator, MedusaError } from "medusa-core-utils"
import { MedusaError } from "medusa-core-utils"
import { BaseService } from "medusa-interfaces"
import { currencies } from "../utils/currencies"
/**
* Provides layer to manipulate store settings.
* @implements BaseService
* @extends BaseService
*/
class StoreService extends BaseService {
constructor({
@@ -52,7 +51,7 @@ class StoreService extends BaseService {
* @return {Promise<Store>} the store.
*/
async create() {
return this.atomicPhase_(async manager => {
return this.atomicPhase_(async (manager) => {
const storeRepository = manager.getCustomRepository(this.storeRepository_)
let store = await this.retrieve()
@@ -68,6 +67,7 @@ class StoreService extends BaseService {
/**
* Retrieve the store settings. There is always a maximum of one store.
* @param {string[]} relations - relations to fetch with store
* @return {Promise<Store>} the store
*/
async retrieve(relations = []) {
@@ -90,16 +90,12 @@ class StoreService extends BaseService {
}
/**
* Updates a customer. Metadata updates and address updates should
* use dedicated methods, e.g. `setMetadata`, etc. The function
* will throw errors if metadata updates and address updates are attempted.
* @param {string} variantId - the id of the variant. Must be a string that
* can be casted to an ObjectId
* Updates a store
* @param {object} update - an object with the update values.
* @return {Promise} resolves to the update result.
*/
async update(update) {
return this.atomicPhase_(async manager => {
return this.atomicPhase_(async (manager) => {
const storeRepository = manager.getCustomRepository(this.storeRepository_)
const currencyRepository = manager.getCustomRepository(
this.currencyRepository_
@@ -109,7 +105,6 @@ class StoreService extends BaseService {
const {
metadata,
default_currency,
default_currency_code,
currencies: storeCurrencies,
...rest
@@ -137,7 +132,7 @@ class StoreService extends BaseService {
if (storeCurrencies) {
store.currencies = await Promise.all(
storeCurrencies.map(async curr => {
storeCurrencies.map(async (curr) => {
const currency = await currencyRepository.findOne({
where: { code: curr.toLowerCase() },
})
@@ -169,7 +164,7 @@ class StoreService extends BaseService {
* @return {Promise} result after update
*/
async addCurrency(code) {
return this.atomicPhase_(async manager => {
return this.atomicPhase_(async (manager) => {
const storeRepo = manager.getCustomRepository(this.storeRepository_)
const currencyRepository = manager.getCustomRepository(
this.currencyRepository_
@@ -187,7 +182,9 @@ class StoreService extends BaseService {
)
}
if (store.currencies.map(c => c.code).includes(curr.code.toLowerCase())) {
if (
store.currencies.map((c) => c.code).includes(curr.code.toLowerCase())
) {
throw new MedusaError(
MedusaError.Types.DUPLICATE_ERROR,
`Currency already added`
@@ -206,17 +203,17 @@ class StoreService extends BaseService {
* @return {Promise} result after update
*/
async removeCurrency(code) {
return this.atomicPhase_(async manager => {
return this.atomicPhase_(async (manager) => {
const storeRepo = manager.getCustomRepository(this.storeRepository_)
const store = await this.retrieve(["currencies"])
const exists = store.currencies.find(c => c.code === code.toLowerCase())
const exists = store.currencies.find((c) => c.code === code.toLowerCase())
// If currency does not exist, return early
if (!exists) {
return store
}
store.currencies = store.currencies.filter(c => c.code !== code)
store.currencies = store.currencies.filter((c) => c.code !== code)
const updated = await storeRepo.save(store)
return updated
})