hotfix(medusa): shipping option metadata (#110)
* hotfix(medusa): allow metadata update of shipping options * fix: typo
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import _ from "lodash"
|
||||
import { MedusaError, Validator } from "medusa-core-utils"
|
||||
|
||||
export default async (req, res) => {
|
||||
@@ -18,6 +19,7 @@ export default async (req, res) => {
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
metadata: Validator.object().optional(),
|
||||
})
|
||||
|
||||
const { value, error } = schema.validate(req.body)
|
||||
@@ -27,7 +29,16 @@ export default async (req, res) => {
|
||||
|
||||
try {
|
||||
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)
|
||||
|
||||
res.status(200).json({ shipping_option: data })
|
||||
} catch (err) {
|
||||
throw err
|
||||
|
||||
@@ -226,7 +226,7 @@ class ShippingOptionService extends BaseService {
|
||||
* Validates a shipping option price
|
||||
* @param {ShippingOptionPrice} price - the price to validate
|
||||
* @param {ShippingOption} option - the option to validate against
|
||||
* @return {ShippingOptionPrice} the validated price
|
||||
* @return {Promise<ShippingOptionPrice>} the validated price
|
||||
*/
|
||||
async validatePrice_(price, option) {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user