From 71561b0a6171517800adf52ce9388e121ae08af5 Mon Sep 17 00:00:00 2001 From: Lucifer <63491234+ashish-patwal@users.noreply.github.com> Date: Mon, 25 Oct 2021 12:41:28 +0530 Subject: [PATCH] chore: Make packages/medusa/src/services/product.js (#585) --- .eslintignore | 1 - packages/medusa/src/services/product.js | 24 +++++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/.eslintignore b/.eslintignore index c4f9bb861a..5e104a0791 100644 --- a/.eslintignore +++ b/.eslintignore @@ -6,7 +6,6 @@ /packages/medusa/src/services/middleware.js /packages/medusa/src/services/payment-provider.js /packages/medusa/src/services/product-variant.js -/packages/medusa/src/services/product.js /packages/medusa/src/services/shipping-profile.js /packages/medusa/src/subscribers/notification.js /packages/medusa/src/subscribers/order.js diff --git a/packages/medusa/src/services/product.js b/packages/medusa/src/services/product.js index 54e1ebea6f..bdb1d83ded 100644 --- a/packages/medusa/src/services/product.js +++ b/packages/medusa/src/services/product.js @@ -1,11 +1,10 @@ -import _ from "lodash" import { MedusaError } from "medusa-core-utils" import { BaseService } from "medusa-interfaces" import { Brackets } from "typeorm" /** * Provides layer to manipulate products. - * @implements BaseService + * @extends BaseService */ class ProductService extends BaseService { static IndexName = `products` @@ -88,7 +87,8 @@ class ProductService extends BaseService { } /** - * @param {Object} listOptions - the query object for find + * @param {object} selector - selector for query + * @param {Object} config - config for query object for find * @return {Promise} the result of the find operation */ async list(selector = {}, config = { relations: [], skip: 0, take: 20 }) { @@ -112,7 +112,7 @@ class ProductService extends BaseService { query.select = config.select } - let rels = query.relations + const rels = query.relations delete query.relations if (q) { @@ -162,6 +162,7 @@ class ProductService extends BaseService { * Gets a product by id. * Throws in case of DB Error and if product was not found. * @param {string} productId - id of the product to get. + * @param {object} config - config of the product to get. * @return {Promise} the result of the find one operation. */ async retrieve(productId, config = {}) { @@ -258,7 +259,7 @@ class ProductService extends BaseService { this.productTagRepository_ ) - let newTags = [] + const newTags = [] for (const tag of tags) { const existing = await productTagRepository.findOne({ where: { value: tag.value }, @@ -339,7 +340,7 @@ class ProductService extends BaseService { this.imageRepository_ ) - let productImages = [] + const productImages = [] for (const img of images) { const existing = await imageRepository.findOne({ where: { url: img }, @@ -376,8 +377,7 @@ class ProductService extends BaseService { relations: ["variants", "tags", "images"], }) - const { variants, metadata, options, images, tags, type, ...rest } = - update + const { variants, metadata, images, tags, type, ...rest } = update if (!product.thumbnail && !update.thumbnail && images?.length) { product.thumbnail = images[0] @@ -473,7 +473,9 @@ class ProductService extends BaseService { { relations: ["variants"] } ) - if (!product) return Promise.resolve() + if (!product) { + return Promise.resolve() + } await productRepo.softRemove(product) @@ -574,7 +576,7 @@ class ProductService extends BaseService { * optionOrder and the length of the product's options are different. Will * throw optionOrder contains an id not associated with the product. * @param {string} productId - the product whose options we are reordering - * @param {[ObjectId]} optionId - the ids of the product's options in the + * @param {string[]} optionOrder - the ids of the product's options in the * new order * @return {Promise} the result of the update operation */ @@ -727,7 +729,7 @@ class ProductService extends BaseService { /** * Decorates a product with product variants. - * @param {Product} product - the product to decorate. + * @param {string} productId - the productId to decorate. * @param {string[]} fields - the fields to include. * @param {string[]} expandFields - fields to expand. * @return {Product} return the decorated product.