hotfix(medusa): shipping option metadata (#110)

* hotfix(medusa): allow metadata update of shipping options

* fix: typo
This commit is contained in:
Sebastian Rindom
2020-09-21 11:44:57 +02:00
committed by GitHub
parent b217a5c111
commit 15bcc1d68c
2 changed files with 12 additions and 1 deletions
@@ -1,3 +1,4 @@
import _ from "lodash"
import { MedusaError, Validator } from "medusa-core-utils" import { MedusaError, Validator } from "medusa-core-utils"
export default async (req, res) => { export default async (req, res) => {
@@ -18,6 +19,7 @@ export default async (req, res) => {
}) })
) )
.optional(), .optional(),
metadata: Validator.object().optional(),
}) })
const { value, error } = schema.validate(req.body) const { value, error } = schema.validate(req.body)
@@ -27,7 +29,16 @@ export default async (req, res) => {
try { try {
const optionService = req.scope.resolve("shippingOptionService") const optionService = req.scope.resolve("shippingOptionService")
if (!_.isEmpty(value.metadata)) {
for (let key of Object.keys(value.metadata)) {
await optionService.setMetadata(option_id, key, value.metadata[key])
}
delete value.metadata
}
const data = await optionService.update(option_id, value) const data = await optionService.update(option_id, value)
res.status(200).json({ shipping_option: data }) res.status(200).json({ shipping_option: data })
} catch (err) { } catch (err) {
throw err throw err
@@ -226,7 +226,7 @@ class ShippingOptionService extends BaseService {
* Validates a shipping option price * Validates a shipping option price
* @param {ShippingOptionPrice} price - the price to validate * @param {ShippingOptionPrice} price - the price to validate
* @param {ShippingOption} option - the option to validate against * @param {ShippingOption} option - the option to validate against
* @return {ShippingOptionPrice} the validated price * @return {Promise<ShippingOptionPrice>} the validated price
*/ */
async validatePrice_(price, option) { async validatePrice_(price, option) {
if ( if (