Moves Medusa interfaces defines model schemas for Customer, Cart, Order
This commit is contained in:
1 parent
751adec7f7
commit
edce88c34b
26 files changed
+147
-19
No files matched your search
@@ -1,11 +1,12 @@
|
||||
/*******************************************************************************
|
||||
* models/product-variant.js
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "../interfaces"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
import LineItemSchema from "./schemas/line-item"
|
||||
import PaymentMethodSchema from "./schemas/payment-method"
|
||||
import ShippingMethodSchema from "./schemas/shipping-method"
|
||||
import AddressSchema from "./schemas/address"
|
||||
|
||||
class CartModel extends BaseModel {
|
||||
@@ -13,12 +14,15 @@ class CartModel extends BaseModel {
|
||||
|
||||
static schema = {
|
||||
email: { type: String },
|
||||
billingAddress: { type: AddressSchema },
|
||||
shippingAddress: { type: AddressSchema },
|
||||
items: { type: [LinetItemSchema], default: [] },
|
||||
billing_address: { type: AddressSchema },
|
||||
shipping_address: { type: AddressSchema },
|
||||
items: { type: [LineItemSchema], default: [] },
|
||||
region: { type: String, required: true },
|
||||
discounts: { type: [String], default: true },
|
||||
discounts: { type: [String], default: [] },
|
||||
customer_id: { type: String },
|
||||
payment_method: { type: PaymentMethodSchema },
|
||||
shipping_methods: { type: [ShippingMethodSchema] },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
import AddressSchema from "./schemas/address"
|
||||
|
||||
class CustomerModel extends BaseModel {
|
||||
static modelName = "Customer"
|
||||
|
||||
static schema = {
|
||||
email: { type: String, required: true, unique: true },
|
||||
first_name: { type: String, required: true },
|
||||
last_name: { type: String, required: true },
|
||||
billingAddress: { type: AddressSchema },
|
||||
password_hash: { type: String },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
}
|
||||
}
|
||||
|
||||
export default CustomerModel
|
||||
@@ -0,0 +1,31 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
import LineItemSchema from "./schemas/line-item"
|
||||
import PaymentMethodSchema from "./schemas/payment-method"
|
||||
import ShippingMethodSchema from "./schemas/shipping-method"
|
||||
import AddressSchema from "./schemas/address"
|
||||
|
||||
class OrderModel extends BaseModel {
|
||||
static modelName = "Order"
|
||||
|
||||
static schema = {
|
||||
canceled: { type: Boolean, default: false },
|
||||
archived: { type: Boolean, default: false },
|
||||
email: { type: String, required: true },
|
||||
billing_address: { type: AddressSchema, required: true },
|
||||
shipping_address: { type: AddressSchema, required: true },
|
||||
items: { type: [LineItemSchema], required: true },
|
||||
region: { type: String, required: true },
|
||||
discounts: { type: [String], default: [] },
|
||||
customer_id: { type: String, required: true },
|
||||
payment_method: { type: PaymentMethodSchema, required: true },
|
||||
shipping_methods: { type: [ShippingMethodSchema], required: true },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
}
|
||||
}
|
||||
|
||||
export default OrderModel
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "../interfaces"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
import MoneyAmountSchema from "./schemas/money-amount"
|
||||
import OptionValueSchema from "./schemas/option-value"
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "../interfaces"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
import OptionSchema from "./schemas/option"
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ export default new mongoose.Schema({
|
||||
// mongoose doesn't allow multi-type validation but this field allows both
|
||||
// an object containing:
|
||||
// {
|
||||
// unit_price: (MoneyAmount),
|
||||
// variant: (ProductVariantSchema),
|
||||
// product: (ProductSchema)
|
||||
// }
|
||||
@@ -18,11 +19,17 @@ export default new mongoose.Schema({
|
||||
// and and array containing:
|
||||
// [
|
||||
// {
|
||||
// unit_price: (MoneyAmount),
|
||||
// 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 },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
provider_id: { type: String, required: true },
|
||||
data: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
})
|
||||
@@ -0,0 +1,9 @@
|
||||
/*******************************************************************************
|
||||
*
|
||||
******************************************************************************/
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
provider_id: { type: String, required: true },
|
||||
data: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
})
|
||||
@@ -2,7 +2,7 @@
|
||||
* models/user.js
|
||||
*
|
||||
******************************************************************************/
|
||||
import { BaseModel } from "../interfaces"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
class UserModel extends BaseModel {
|
||||
static modelName = "User"
|
||||
|
||||
Reference in new issue
Block a user