chore: Make packages/medusa/src/services/product.js (#585)

This commit is contained in:
Lucifer
2021-10-25 09:11:28 +02:00
committed by GitHub
parent 7cc94dc479
commit 71561b0a61
2 changed files with 13 additions and 12 deletions
-1
View File
@@ -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
+13 -11
View File
@@ -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<Product>} 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.