feat(medusa-interfaces): Adds schema options to base model
This commit is contained in:
committed by
GitHub
parent
883e80a038
commit
cc23a3b070
@@ -35,13 +35,30 @@ class BaseModel {
|
||||
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
|
||||
* 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
|
||||
*/
|
||||
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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,10 @@ import DiscountSchema from "./schemas/discount"
|
||||
class CartModel extends BaseModel {
|
||||
static modelName = "Cart"
|
||||
|
||||
static schemaOptions = {
|
||||
minimize: false,
|
||||
}
|
||||
|
||||
static schema = {
|
||||
email: { type: String },
|
||||
billing_address: { type: AddressSchema },
|
||||
|
||||
Reference in New Issue
Block a user