feat(medusa-interfaces): Adds schema options to base model

This commit is contained in:
Oliver Windall Juhl authored and GitHub committed 2020-10-20 17:07:47 +02:00
1 parent 883e80a038
commit cc23a3b070
2 files changed
+23 -2

No files matched your search

+19 -2
View File
@@ -35,13 +35,30 @@ class BaseModel {
return this.constructor.modelName return this.constructor.modelName
} }
/**
* Returns the schema options defined in child class.
* @return {object} the schema options
*/
getSchemaOptions() {
if (!this.constructor.schemaOptions) {
return {}
}
return this.constructor.schemaOptions
}
/** /**
* @private * @private
* Creates a mongoose model based on schema and model name. * Creates a mongoose model based on schema, schema options and model name.
* @return {Mongooose.Model} the mongoose model * @return {Mongooose.Model} the mongoose model
*/ */
createMongooseModel_() { createMongooseModel_() {
return mongoose.model(this.getModelName(), this.getSchema()) const schema = this.getSchema()
const options = this.getSchemaOptions()
const mongooseSchema = new mongoose.Schema(schema, options)
return mongoose.model(this.getModelName(), mongooseSchema)
} }
/** /**
+4
View File
@@ -13,6 +13,10 @@ import DiscountSchema from "./schemas/discount"
class CartModel extends BaseModel { class CartModel extends BaseModel {
static modelName = "Cart" static modelName = "Cart"
static schemaOptions = {
minimize: false,
}
static schema = { static schema = {
email: { type: String }, email: { type: String },
billing_address: { type: AddressSchema }, billing_address: { type: AddressSchema },