From 46dbbdb9fbe1594d02522f2ff21a0adbd2cb2179 Mon Sep 17 00:00:00 2001 From: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Date: Sat, 17 Oct 2020 17:06:20 +0200 Subject: [PATCH] hotfix(medusa): Save empty metadata on line-items (#126) --- .../medusa/src/models/schemas/line-item.js | 79 ++++++++++--------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/packages/medusa/src/models/schemas/line-item.js b/packages/medusa/src/models/schemas/line-item.js index 85ed586c54..5a9c3df868 100644 --- a/packages/medusa/src/models/schemas/line-item.js +++ b/packages/medusa/src/models/schemas/line-item.js @@ -3,42 +3,45 @@ ******************************************************************************/ import mongoose from "mongoose" -export default new mongoose.Schema({ - title: { type: String, required: true }, - description: { type: String }, - thumbnail: { type: String }, - is_giftcard: { type: Boolean, default: false }, - should_merge: { type: Boolean, default: true }, - has_shipping: { type: Boolean, default: false }, +export default new mongoose.Schema( + { + title: { type: String, required: true }, + description: { type: String }, + thumbnail: { type: String }, + is_giftcard: { type: Boolean, default: false }, + should_merge: { type: Boolean, default: true }, + has_shipping: { type: Boolean, default: false }, - // mongoose doesn't allow multi-type validation but this field allows both - // an object containing: - // { - // unit_price: (MoneyAmount), - // variant: (ProductVariantSchema), - // product: (ProductSchema) - // } - // - // and and array containing: - // [ - // { - // unit_price: (MoneyAmount), - // quantity: (Number), - // variant: (ProductVariantSchema), - // product: (ProductSchema) - // } - // ] - // validation is done in the cart service. - // - // The unit_price field can be used to override the default pricing mechanism. - // By default the price will be set based on the variant(s) in content, - // however, to allow line items with variable pricing e.g. limited sales, gift - // cards etc. the unit_price field is provided to give more granular control. - content: { type: mongoose.Schema.Types.Mixed, required: true }, - quantity: { type: Number, required: true }, - returned: { type: Boolean, default: false }, - fulfilled: { type: Boolean, default: false }, - fulfilled_quantity: { type: Number, default: 0 }, - returned_quantity: { type: Number, default: 0 }, - metadata: { type: mongoose.Schema.Types.Mixed, default: {} }, -}) + // mongoose doesn't allow multi-type validation but this field allows both + // an object containing: + // { + // unit_price: (MoneyAmount), + // variant: (ProductVariantSchema), + // product: (ProductSchema) + // } + // + // and and array containing: + // [ + // { + // unit_price: (MoneyAmount), + // quantity: (Number), + // variant: (ProductVariantSchema), + // product: (ProductSchema) + // } + // ] + // validation is done in the cart service. + // + // The unit_price field can be used to override the default pricing mechanism. + // By default the price will be set based on the variant(s) in content, + // however, to allow line items with variable pricing e.g. limited sales, gift + // cards etc. the unit_price field is provided to give more granular control. + content: { type: mongoose.Schema.Types.Mixed, required: true }, + quantity: { type: Number, required: true }, + returned: { type: Boolean, default: false }, + fulfilled: { type: Boolean, default: false }, + fulfilled_quantity: { type: Number, default: 0 }, + returned_quantity: { type: Number, default: 0 }, + metadata: { type: mongoose.Schema.Types.Mixed, default: {} }, + }, + { minimize: false } +)