Moves Medusa interfaces defines model schemas for Customer, Cart, Order
This commit is contained in:
1
packages/medusa-core-utils/.gitignore
vendored
1
packages/medusa-core-utils/.gitignore
vendored
@@ -1 +1,2 @@
|
||||
dist/
|
||||
node_modules/
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
"@babel/plugin-proposal-class-properties": "^7.7.4",
|
||||
"@babel/plugin-transform-runtime": "^7.7.6",
|
||||
"@babel/preset-env": "^7.7.5",
|
||||
"client-sessions": "^0.8.0",
|
||||
"cross-env": "^5.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
|
||||
9
packages/medusa-interfaces/.babelrc
Normal file
9
packages/medusa-interfaces/.babelrc
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"plugins": ["@babel/plugin-proposal-class-properties"],
|
||||
"presets": ["@babel/preset-env"],
|
||||
"env": {
|
||||
"test": {
|
||||
"plugins": ["@babel/plugin-transform-runtime"]
|
||||
}
|
||||
}
|
||||
}
|
||||
7
packages/medusa-interfaces/.gitignore
vendored
Normal file
7
packages/medusa-interfaces/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
dist/
|
||||
node_modules/
|
||||
.DS_store
|
||||
.env*
|
||||
/*.js
|
||||
!index.js
|
||||
yarn.lock
|
||||
29
packages/medusa-interfaces/package.json
Normal file
29
packages/medusa-interfaces/package.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"name": "medusa-interfaces",
|
||||
"version": "1.0.0",
|
||||
"description": "Core interfaces for Medusa",
|
||||
"main": "dist/index.js",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/srindom/medusa",
|
||||
"directory": "packages/medusa-interfaces"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel src --out-dir dist/ --ignore **/__tests__",
|
||||
"prepare": "cross-env NODE_ENV=production npm run build",
|
||||
"watch": "babel -w src --out-dir dist/ --ignore **/__tests__"
|
||||
},
|
||||
"author": "Sebastian Rindom",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"devDependencies": {
|
||||
"@babel/cli": "^7.7.5",
|
||||
"@babel/core": "^7.7.5",
|
||||
"@babel/plugin-proposal-class-properties": "^7.7.4",
|
||||
"@babel/plugin-transform-runtime": "^7.7.6",
|
||||
"@babel/preset-env": "^7.7.5",
|
||||
"cross-env": "^5.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"mongoose": "^5.8.0"
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export { default as BaseService } from "./base-service"
|
||||
export { default as BaseModel } from "./base-model"
|
||||
export { default as PaymentService } from "./payment-service"
|
||||
@@ -25,6 +25,7 @@
|
||||
"watch": "babel -w src --out-dir . --ignore **/__tests__"
|
||||
},
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.7.6"
|
||||
"@babel/runtime": "^7.7.6",
|
||||
"medusa-interfaces": "^1.0.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ from "lodash"
|
||||
import PaymentService from "../../../src/interfaces/payment-service"
|
||||
import { PaymentService } from "medusa-interfaces"
|
||||
|
||||
class StripeProviderService extends PaymentService {
|
||||
static identifier = "stripe"
|
||||
|
||||
@@ -49,6 +49,7 @@
|
||||
"joi-objectid": "^3.0.1",
|
||||
"jsonwebtoken": "^8.5.1",
|
||||
"medusa-core-utils": "^1.0.0",
|
||||
"medusa-interfaces": "^1.0.0",
|
||||
"mongoose": "^5.8.0",
|
||||
"morgan": "^1.9.1",
|
||||
"passport": "^0.4.0",
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import glob from "glob"
|
||||
import { BaseModel, BaseService, PaymentService } from "medusa-interfaces"
|
||||
import _ from "lodash"
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import { asFunction } from "awilix"
|
||||
import { sync as existsSync } from "fs-exists-cached"
|
||||
import { plugins } from "../../medusa-config.js"
|
||||
import PaymentService from "../interfaces/payment-service"
|
||||
import BaseModel from "../interfaces/base-model"
|
||||
import BaseService from "../interfaces/base-service"
|
||||
|
||||
/**
|
||||
* Registers all services in the services directory
|
||||
|
||||
@@ -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: {} },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
22
packages/medusa/src/models/customer.js
Normal file
22
packages/medusa/src/models/customer.js
Normal file
@@ -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
|
||||
31
packages/medusa/src/models/order.js
Normal file
31
packages/medusa/src/models/order.js
Normal file
@@ -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: {} },
|
||||
|
||||
9
packages/medusa/src/models/schemas/payment-method.js
Normal file
9
packages/medusa/src/models/schemas/payment-method.js
Normal file
@@ -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: {} },
|
||||
})
|
||||
9
packages/medusa/src/models/schemas/shipping-method.js
Normal file
9
packages/medusa/src/models/schemas/shipping-method.js
Normal file
@@ -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"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import bcrypt from "bcrypt"
|
||||
import { BaseService } from "../interfaces"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
|
||||
/**
|
||||
* Can authenticate a user based on email password combination
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import mongoose from "mongoose"
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "../interfaces"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate carts.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import _ from "lodash"
|
||||
import { BaseService } from "../interfaces"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import mongoose from "mongoose"
|
||||
import _ from "lodash"
|
||||
import { Validator, MedusaError } from "medusa-core-utils"
|
||||
import { BaseService } from "../interfaces"
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
|
||||
/**
|
||||
* Provides layer to manipulate products.
|
||||
|
||||
Reference in New Issue
Block a user