From e97367d26eed42cb15ba0216dc25338ab24db893 Mon Sep 17 00:00:00 2001 From: Daniel Tiringer <53534182+danielTiringer@users.noreply.github.com> Date: Mon, 25 Oct 2021 18:01:43 +0000 Subject: [PATCH] Fix linting errors in routes admin product (#656) --- .eslintignore | 1 - .../api/routes/admin/products/add-option.js | 18 +- .../routes/admin/products/create-product.js | 179 +++++++----------- .../routes/admin/products/create-variant.js | 40 ++-- .../routes/admin/products/delete-option.js | 28 ++- .../routes/admin/products/delete-product.js | 18 +- .../routes/admin/products/delete-variant.js | 30 ++- .../src/api/routes/admin/products/index.js | 2 +- .../routes/admin/products/list-products.js | 85 ++++----- .../admin/products/list-tag-usage-count.js | 10 +- .../api/routes/admin/products/list-types.js | 10 +- .../api/routes/admin/products/set-metadata.js | 22 +-- .../routes/admin/products/update-option.js | 18 +- .../routes/admin/products/update-product.js | 77 +++----- .../routes/admin/products/update-variant.js | 58 ++---- 15 files changed, 225 insertions(+), 371 deletions(-) diff --git a/.eslintignore b/.eslintignore index 5e3f4d205f..9b032b65de 100644 --- a/.eslintignore +++ b/.eslintignore @@ -35,7 +35,6 @@ /packages/medusa/src/api/routes/admin/notes /packages/medusa/src/api/routes/admin/notifications /packages/medusa/src/api/routes/admin/orders -/packages/medusa/src/api/routes/admin/products /packages/medusa/src/api/routes/admin/regions /packages/medusa/src/api/routes/admin/return-reasons /packages/medusa/src/api/routes/admin/returns diff --git a/packages/medusa/src/api/routes/admin/products/add-option.js b/packages/medusa/src/api/routes/admin/products/add-option.js index c7f9e5291c..cfe4ba273a 100644 --- a/packages/medusa/src/api/routes/admin/products/add-option.js +++ b/packages/medusa/src/api/routes/admin/products/add-option.js @@ -39,17 +39,13 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productService = req.scope.resolve("productService") + const productService = req.scope.resolve("productService") - await productService.addOption(id, value.title) - const product = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + await productService.addOption(id, value.title) + const product = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.json({ product }) - } catch (err) { - throw err - } + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/create-product.js b/packages/medusa/src/api/routes/admin/products/create-product.js index d02ac8fb7d..86c6004ff1 100644 --- a/packages/medusa/src/api/routes/admin/products/create-product.js +++ b/packages/medusa/src/api/routes/admin/products/create-product.js @@ -188,9 +188,7 @@ export default async (req, res) => { description: Validator.string().allow(""), is_giftcard: Validator.boolean().default(false), discountable: Validator.boolean().default(true), - images: Validator.array() - .items(Validator.string()) - .optional(), + images: Validator.array().items(Validator.string()).optional(), thumbnail: Validator.string().optional(), handle: Validator.string().optional(), status: Validator.string() @@ -203,9 +201,7 @@ export default async (req, res) => { }) .allow(null) .optional(), - collection_id: Validator.string() - .allow(null) - .optional(), + collection_id: Validator.string().allow(null).optional(), tags: Validator.array() .items({ id: Validator.string().optional(), @@ -225,30 +221,13 @@ export default async (req, res) => { inventory_quantity: Validator.number().default(0), allow_backorder: Validator.boolean().optional(), manage_inventory: Validator.boolean().optional(), - weight: Validator.number() - .allow(null) - .optional(), - length: Validator.number() - .allow(null) - .optional(), - height: Validator.number() - .allow(null) - .optional(), - width: Validator.number() - .allow(null) - .optional(), - origin_country: Validator.string() - .optional() - .allow("") - .allow(null), - mid_code: Validator.string() - .optional() - .allow("") - .allow(null), - material: Validator.string() - .optional() - .allow("") - .allow(null), + weight: Validator.number().allow(null).optional(), + length: Validator.number().allow(null).optional(), + height: Validator.number().allow(null).optional(), + width: Validator.number().allow(null).optional(), + origin_country: Validator.string().optional().allow("").allow(null), + mid_code: Validator.string().optional().allow("").allow(null), + material: Validator.string().optional().allow("").allow(null), metadata: Validator.object().optional(), prices: Validator.array() .items( @@ -256,9 +235,7 @@ export default async (req, res) => { .keys({ region_id: Validator.string(), currency_code: Validator.string(), - amount: Validator.number() - .integer() - .required(), + amount: Validator.number().integer().required(), sale_amount: Validator.number().optional(), }) .xor("region_id", "currency_code") @@ -270,30 +247,14 @@ export default async (req, res) => { }) .default([]), }), - weight: Validator.number() - .allow(null) - .optional(), - length: Validator.number() - .allow(null) - .optional(), - height: Validator.number() - .allow(null) - .optional(), - width: Validator.number() - .allow(null) - .optional(), - hs_code: Validator.string() - .optional() - .allow(""), - origin_country: Validator.string() - .optional() - .allow(""), - mid_code: Validator.string() - .optional() - .allow(""), - material: Validator.string() - .optional() - .allow(""), + weight: Validator.number().allow(null).optional(), + length: Validator.number().allow(null).optional(), + height: Validator.number().allow(null).optional(), + width: Validator.number().allow(null).optional(), + hs_code: Validator.string().optional().allow(""), + origin_country: Validator.string().optional().allow(""), + mid_code: Validator.string().optional().allow(""), + material: Validator.string().optional().allow(""), metadata: Validator.object().optional(), }) @@ -302,66 +263,64 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productService = req.scope.resolve("productService") - const productVariantService = req.scope.resolve("productVariantService") - const shippingProfileService = req.scope.resolve("shippingProfileService") + const productService = req.scope.resolve("productService") + const productVariantService = req.scope.resolve("productVariantService") + const shippingProfileService = req.scope.resolve("shippingProfileService") - const entityManager = req.scope.resolve("manager") + const entityManager = req.scope.resolve("manager") - let newProduct - await entityManager.transaction(async manager => { - const { variants } = value - delete value.variants + let newProduct + await entityManager.transaction(async (manager) => { + const { variants } = value + delete value.variants - if (!value.thumbnail && value.images && value.images.length) { - value.thumbnail = value.images[0] + if (!value.thumbnail && value.images && value.images.length) { + value.thumbnail = value.images[0] + } + + let shippingProfile + // Get default shipping profile + if (value.is_giftcard) { + shippingProfile = await shippingProfileService.retrieveGiftCardDefault() + } else { + shippingProfile = await shippingProfileService.retrieveDefault() + } + + newProduct = await productService + .withTransaction(manager) + .create({ ...value, profile_id: shippingProfile.id }) + + if (variants) { + for (const [i, variant] of variants.entries()) { + variant.variant_rank = i } - let shippingProfile - // Get default shipping profile - if (value.is_giftcard) { - shippingProfile = await shippingProfileService.retrieveGiftCardDefault() - } else { - shippingProfile = await shippingProfileService.retrieveDefault() - } + const optionIds = value.options.map( + (o) => newProduct.options.find((newO) => newO.title === o.title).id + ) - newProduct = await productService - .withTransaction(manager) - .create({ ...value, profile_id: shippingProfile.id }) + await Promise.all( + variants.map(async (v) => { + const variant = { + ...v, + options: v.options.map((o, index) => ({ + ...o, + option_id: optionIds[index], + })), + } - if (variants) { - for (const [i, variant] of variants.entries()) variant.variant_rank = i + await productVariantService + .withTransaction(manager) + .create(newProduct.id, variant) + }) + ) + } + }) - const optionIds = value.options.map( - o => newProduct.options.find(newO => newO.title === o.title).id - ) + const product = await productService.retrieve(newProduct.id, { + select: defaultFields, + relations: defaultRelations, + }) - await Promise.all( - variants.map(async v => { - const variant = { - ...v, - options: v.options.map((o, index) => ({ - ...o, - option_id: optionIds[index], - })), - } - - await productVariantService - .withTransaction(manager) - .create(newProduct.id, variant) - }) - ) - } - }) - - const product = await productService.retrieve(newProduct.id, { - select: defaultFields, - relations: defaultRelations, - }) - - res.json({ product }) - } catch (err) { - throw err - } + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/create-variant.js b/packages/medusa/src/api/routes/admin/products/create-variant.js index a45722cd0c..d6ad39e100 100644 --- a/packages/medusa/src/api/routes/admin/products/create-variant.js +++ b/packages/medusa/src/api/routes/admin/products/create-variant.js @@ -115,18 +115,10 @@ export default async (req, res) => { inventory_quantity: Validator.number().default(0), allow_backorder: Validator.boolean().optional(), manage_inventory: Validator.boolean().optional(), - weight: Validator.number() - .allow(null) - .optional(), - length: Validator.number() - .allow(null) - .optional(), - height: Validator.number() - .allow(null) - .optional(), - width: Validator.number() - .allow(null) - .optional(), + weight: Validator.number().allow(null).optional(), + length: Validator.number().allow(null).optional(), + height: Validator.number().allow(null).optional(), + width: Validator.number().allow(null).optional(), origin_country: Validator.string().allow(""), mid_code: Validator.string().allow(""), material: Validator.string().allow(""), @@ -137,9 +129,7 @@ export default async (req, res) => { .keys({ region_id: Validator.string().empty(null), currency_code: Validator.string().required(), - amount: Validator.number() - .integer() - .required(), + amount: Validator.number().integer().required(), sale_amount: Validator.number().optional(), }) .xor("region_id", "currency_code") @@ -158,19 +148,15 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productVariantService = req.scope.resolve("productVariantService") - const productService = req.scope.resolve("productService") + const productVariantService = req.scope.resolve("productVariantService") + const productService = req.scope.resolve("productService") - await productVariantService.create(id, value) + await productVariantService.create(id, value) - const product = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + const product = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.json({ product }) - } catch (err) { - throw err - } + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/delete-option.js b/packages/medusa/src/api/routes/admin/products/delete-option.js index 8b8911713e..2e5e4ce25e 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-option.js +++ b/packages/medusa/src/api/routes/admin/products/delete-option.js @@ -31,21 +31,17 @@ import { defaultRelations, defaultFields } from "." export default async (req, res) => { const { id, option_id } = req.params - try { - const productService = req.scope.resolve("productService") - await productService.deleteOption(id, option_id) - const data = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + const productService = req.scope.resolve("productService") + await productService.deleteOption(id, option_id) + const data = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.json({ - option_id, - object: "option", - deleted: true, - product: data, - }) - } catch (err) { - throw err - } + res.json({ + option_id, + object: "option", + deleted: true, + product: data, + }) } diff --git a/packages/medusa/src/api/routes/admin/products/delete-product.js b/packages/medusa/src/api/routes/admin/products/delete-product.js index a09b99273d..5b87f1d90b 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-product.js +++ b/packages/medusa/src/api/routes/admin/products/delete-product.js @@ -26,15 +26,11 @@ export default async (req, res) => { const { id } = req.params - try { - const productService = req.scope.resolve("productService") - await productService.delete(id) - res.json({ - id, - object: "product", - deleted: true, - }) - } catch (err) { - throw err - } + const productService = req.scope.resolve("productService") + await productService.delete(id) + res.json({ + id, + object: "product", + deleted: true, + }) } diff --git a/packages/medusa/src/api/routes/admin/products/delete-variant.js b/packages/medusa/src/api/routes/admin/products/delete-variant.js index 0381c85f5a..dec7a36628 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-variant.js +++ b/packages/medusa/src/api/routes/admin/products/delete-variant.js @@ -29,24 +29,20 @@ import { defaultRelations, defaultFields } from "." export default async (req, res) => { const { id, variant_id } = req.params - try { - const productVariantService = req.scope.resolve("productVariantService") - const productService = req.scope.resolve("productService") + const productVariantService = req.scope.resolve("productVariantService") + const productService = req.scope.resolve("productService") - await productVariantService.delete(variant_id) + await productVariantService.delete(variant_id) - const data = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + const data = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.json({ - variant_id, - object: "product-variant", - deleted: true, - product: data, - }) - } catch (err) { - throw err - } + res.json({ + variant_id, + object: "product-variant", + deleted: true, + product: data, + }) } diff --git a/packages/medusa/src/api/routes/admin/products/index.js b/packages/medusa/src/api/routes/admin/products/index.js index e32e13d168..54b1deb17a 100644 --- a/packages/medusa/src/api/routes/admin/products/index.js +++ b/packages/medusa/src/api/routes/admin/products/index.js @@ -3,7 +3,7 @@ import middlewares from "../../../middlewares" const route = Router() -export default app => { +export default (app) => { app.use("/products", route) route.post("/", middlewares.wrap(require("./create-product").default)) diff --git a/packages/medusa/src/api/routes/admin/products/list-products.js b/packages/medusa/src/api/routes/admin/products/list-products.js index ea309a43ab..25d1595a3e 100644 --- a/packages/medusa/src/api/routes/admin/products/list-products.js +++ b/packages/medusa/src/api/routes/admin/products/list-products.js @@ -1,4 +1,3 @@ -import _ from "lodash" import { MedusaError, Validator } from "medusa-core-utils" import { defaultFields, defaultRelations, filterableFields } from "./" @@ -42,52 +41,48 @@ export default async (req, res) => { ) } - try { - const productService = req.scope.resolve("productService") + const productService = req.scope.resolve("productService") - const limit = parseInt(req.query.limit) || 50 - const offset = parseInt(req.query.offset) || 0 + const limit = parseInt(req.query.limit) || 50 + const offset = parseInt(req.query.offset) || 0 - const selector = {} + const selector = {} - if ("q" in req.query) { - selector.q = req.query.q - } - - let includeFields = [] - if ("fields" in req.query) { - includeFields = req.query.fields.split(",") - } - - let expandFields = [] - if ("expand" in req.query) { - expandFields = req.query.expand.split(",") - } - - for (const k of filterableFields) { - if (k in value) { - selector[k] = value[k] - } - } - - if (selector.status?.indexOf("null") > -1) { - selector.status.splice(selector.status.indexOf("null"), 1) - if (selector.status.length === 0) { - delete selector.status - } - } - - const listConfig = { - select: includeFields.length ? includeFields : defaultFields, - relations: expandFields.length ? expandFields : defaultRelations, - skip: offset, - take: limit, - } - - let products = await productService.list(selector, listConfig) - - res.json({ products, count: products.length, offset, limit }) - } catch (error) { - throw error + if ("q" in req.query) { + selector.q = req.query.q } + + let includeFields = [] + if ("fields" in req.query) { + includeFields = req.query.fields.split(",") + } + + let expandFields = [] + if ("expand" in req.query) { + expandFields = req.query.expand.split(",") + } + + for (const k of filterableFields) { + if (k in value) { + selector[k] = value[k] + } + } + + if (selector.status?.indexOf("null") > -1) { + selector.status.splice(selector.status.indexOf("null"), 1) + if (selector.status.length === 0) { + delete selector.status + } + } + + const listConfig = { + select: includeFields.length ? includeFields : defaultFields, + relations: expandFields.length ? expandFields : defaultRelations, + skip: offset, + take: limit, + } + + const products = await productService.list(selector, listConfig) + + res.json({ products, count: products.length, offset, limit }) } diff --git a/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.js b/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.js index 9bd36ac04d..bb8ed39896 100644 --- a/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.js +++ b/packages/medusa/src/api/routes/admin/products/list-tag-usage-count.js @@ -1,11 +1,7 @@ export default async (req, res) => { - try { - const productService = req.scope.resolve("productService") + const productService = req.scope.resolve("productService") - const tags = await productService.listTagsByUsage() + const tags = await productService.listTagsByUsage() - res.json({ tags }) - } catch (error) { - throw error - } + res.json({ tags }) } diff --git a/packages/medusa/src/api/routes/admin/products/list-types.js b/packages/medusa/src/api/routes/admin/products/list-types.js index d1d3b78f59..1c0cc5d603 100644 --- a/packages/medusa/src/api/routes/admin/products/list-types.js +++ b/packages/medusa/src/api/routes/admin/products/list-types.js @@ -18,13 +18,9 @@ * $ref: "#/components/schemas/product_type" */ export default async (req, res) => { - try { - const productService = req.scope.resolve("productService") + const productService = req.scope.resolve("productService") - const types = await productService.listTypes() + const types = await productService.listTypes() - res.json({ types }) - } catch (error) { - throw error - } + res.json({ types }) } diff --git a/packages/medusa/src/api/routes/admin/products/set-metadata.js b/packages/medusa/src/api/routes/admin/products/set-metadata.js index fbd509e1e7..a25ae4562b 100644 --- a/packages/medusa/src/api/routes/admin/products/set-metadata.js +++ b/packages/medusa/src/api/routes/admin/products/set-metadata.js @@ -14,19 +14,15 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productService = req.scope.resolve("productService") - await productService.update(id, { - metadata: { [value.key]: value.value }, - }) + const productService = req.scope.resolve("productService") + await productService.update(id, { + metadata: { [value.key]: value.value }, + }) - const product = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + const product = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.status(200).json({ product }) - } catch (err) { - throw err - } + res.status(200).json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/update-option.js b/packages/medusa/src/api/routes/admin/products/update-option.js index ecd7e3aa2b..c1c40e53e1 100644 --- a/packages/medusa/src/api/routes/admin/products/update-option.js +++ b/packages/medusa/src/api/routes/admin/products/update-option.js @@ -41,18 +41,14 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productService = req.scope.resolve("productService") + const productService = req.scope.resolve("productService") - await productService.updateOption(id, option_id, value) + await productService.updateOption(id, option_id, value) - const product = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + const product = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.json({ product }) - } catch (err) { - throw err - } + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/update-product.js b/packages/medusa/src/api/routes/admin/products/update-product.js index 85b8f72559..f2022bf5b7 100644 --- a/packages/medusa/src/api/routes/admin/products/update-product.js +++ b/packages/medusa/src/api/routes/admin/products/update-product.js @@ -188,9 +188,7 @@ export default async (req, res) => { const schema = Validator.object().keys({ title: Validator.string().optional(), - subtitle: Validator.string() - .optional() - .allow(null, ""), + subtitle: Validator.string().optional().allow(null, ""), description: Validator.string().optional(), discountable: Validator.boolean().optional(), status: Validator.string().valid( @@ -206,9 +204,7 @@ export default async (req, res) => { }) .allow(null) .optional(), - collection_id: Validator.string() - .allow(null) - .optional(), + collection_id: Validator.string().allow(null).optional(), tags: Validator.array() .items({ id: Validator.string().optional(), @@ -216,26 +212,15 @@ export default async (req, res) => { }) .optional(), handle: Validator.string().optional(), - weight: Validator.number() - .allow(null) - .optional(), - length: Validator.number() - .allow(null) - .optional(), - height: Validator.number() - .allow(null) - .optional(), - width: Validator.number() - .allow(null) - .optional(), + weight: Validator.number().allow(null).optional(), + length: Validator.number().allow(null).optional(), + height: Validator.number().allow(null).optional(), + width: Validator.number().allow(null).optional(), origin_country: Validator.string().allow(null, ""), hs_code: Validator.string().allow(null, ""), mid_code: Validator.string().allow(null, ""), material: Validator.string().allow(null, ""), - images: Validator.array() - .items(Validator.string()) - .optional() - .optional(), + images: Validator.array().items(Validator.string()).optional().optional(), thumbnail: Validator.string().optional(), variants: Validator.array() .items({ @@ -249,9 +234,7 @@ export default async (req, res) => { .keys({ region_id: Validator.string(), currency_code: Validator.string(), - amount: Validator.number() - .integer() - .required(), + amount: Validator.number().integer().required(), sale_amount: Validator.number().optional(), }) .xor("region_id", "currency_code") @@ -266,21 +249,11 @@ export default async (req, res) => { inventory_quantity: Validator.number().allow(null), allow_backorder: Validator.boolean().allow(null), manage_inventory: Validator.boolean().allow(null), - weight: Validator.number() - .allow(null) - .optional(), - length: Validator.number() - .allow(null) - .optional(), - height: Validator.number() - .allow(null) - .optional(), - width: Validator.number() - .allow(null) - .optional(), - hs_code: Validator.string() - .optional() - .allow(null, ""), + weight: Validator.number().allow(null).optional(), + length: Validator.number().allow(null).optional(), + height: Validator.number().allow(null).optional(), + width: Validator.number().allow(null).optional(), + hs_code: Validator.string().optional().allow(null, ""), origin_country: Validator.string().allow(null, ""), mid_code: Validator.string().allow(null, ""), material: Validator.string().allow(null, ""), @@ -295,21 +268,17 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productService = req.scope.resolve("productService") - const entityManager = req.scope.resolve("manager") + const productService = req.scope.resolve("productService") + const entityManager = req.scope.resolve("manager") - await entityManager.transaction(async manager => { - await productService.withTransaction(manager).update(id, value) - }) + await entityManager.transaction(async (manager) => { + await productService.withTransaction(manager).update(id, value) + }) - const product = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) + const product = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) - res.json({ product }) - } catch (err) { - throw err - } + res.json({ product }) } diff --git a/packages/medusa/src/api/routes/admin/products/update-variant.js b/packages/medusa/src/api/routes/admin/products/update-variant.js index 1782ab17be..b70a8a455e 100644 --- a/packages/medusa/src/api/routes/admin/products/update-variant.js +++ b/packages/medusa/src/api/routes/admin/products/update-variant.js @@ -1,4 +1,3 @@ -import _ from "lodash" import { MedusaError, Validator } from "medusa-core-utils" import { defaultFields, defaultRelations } from "./" @@ -116,9 +115,7 @@ export default async (req, res) => { .keys({ region_id: Validator.string().empty(null), currency_code: Validator.string(), - amount: Validator.number() - .integer() - .required(), + amount: Validator.number().integer().required(), sale_amount: Validator.number().optional(), }) .xor("region_id", "currency_code") @@ -133,30 +130,14 @@ export default async (req, res) => { inventory_quantity: Validator.number().optional(), allow_backorder: Validator.boolean().optional(), manage_inventory: Validator.boolean().optional(), - weight: Validator.number() - .allow(null) - .optional(), - length: Validator.number() - .allow(null) - .optional(), - height: Validator.number() - .allow(null) - .optional(), - width: Validator.number() - .allow(null) - .optional(), - hs_code: Validator.string() - .optional() - .allow(null, ""), - origin_country: Validator.string() - .optional() - .allow(null, ""), - mid_code: Validator.string() - .optional() - .allow(null, ""), - material: Validator.string() - .optional() - .allow(null, ""), + weight: Validator.number().allow(null).optional(), + length: Validator.number().allow(null).optional(), + height: Validator.number().allow(null).optional(), + width: Validator.number().allow(null).optional(), + hs_code: Validator.string().optional().allow(null, ""), + origin_country: Validator.string().optional().allow(null, ""), + mid_code: Validator.string().optional().allow(null, ""), + material: Validator.string().optional().allow(null, ""), metadata: Validator.object().optional(), }) @@ -165,18 +146,15 @@ export default async (req, res) => { throw new MedusaError(MedusaError.Types.INVALID_DATA, error.details) } - try { - const productService = req.scope.resolve("productService") - const productVariantService = req.scope.resolve("productVariantService") + const productService = req.scope.resolve("productService") + const productVariantService = req.scope.resolve("productVariantService") - await productVariantService.update(variant_id, value) + await productVariantService.update(variant_id, value) - const product = await productService.retrieve(id, { - select: defaultFields, - relations: defaultRelations, - }) - res.json({ product }) - } catch (err) { - throw err - } + const product = await productService.retrieve(id, { + select: defaultFields, + relations: defaultRelations, + }) + + res.json({ product }) }