Moves Medusa interfaces defines model schemas for Customer, Cart, Order

This commit is contained in:
Sebastian Rindom
2020-01-30 09:38:08 +01:00
parent 751adec7f7
commit edce88c34b
26 changed files with 147 additions and 19 deletions

View File

@@ -1 +1,2 @@
dist/ dist/
node_modules/

View File

@@ -21,7 +21,6 @@
"@babel/plugin-proposal-class-properties": "^7.7.4", "@babel/plugin-proposal-class-properties": "^7.7.4",
"@babel/plugin-transform-runtime": "^7.7.6", "@babel/plugin-transform-runtime": "^7.7.6",
"@babel/preset-env": "^7.7.5", "@babel/preset-env": "^7.7.5",
"client-sessions": "^0.8.0",
"cross-env": "^5.2.1" "cross-env": "^5.2.1"
}, },
"dependencies": { "dependencies": {

View 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
View File

@@ -0,0 +1,7 @@
dist/
node_modules/
.DS_store
.env*
/*.js
!index.js
yarn.lock

View 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"
}
}

View File

@@ -1,2 +1,3 @@
export { default as BaseService } from "./base-service" export { default as BaseService } from "./base-service"
export { default as BaseModel } from "./base-model" export { default as BaseModel } from "./base-model"
export { default as PaymentService } from "./payment-service"

View File

@@ -25,6 +25,7 @@
"watch": "babel -w src --out-dir . --ignore **/__tests__" "watch": "babel -w src --out-dir . --ignore **/__tests__"
}, },
"dependencies": { "dependencies": {
"@babel/runtime": "^7.7.6" "@babel/runtime": "^7.7.6",
"medusa-interfaces": "^1.0.0"
} }
} }

View File

@@ -1,5 +1,5 @@
import _ from "lodash" import _ from "lodash"
import PaymentService from "../../../src/interfaces/payment-service" import { PaymentService } from "medusa-interfaces"
class StripeProviderService extends PaymentService { class StripeProviderService extends PaymentService {
static identifier = "stripe" static identifier = "stripe"

View File

@@ -49,6 +49,7 @@
"joi-objectid": "^3.0.1", "joi-objectid": "^3.0.1",
"jsonwebtoken": "^8.5.1", "jsonwebtoken": "^8.5.1",
"medusa-core-utils": "^1.0.0", "medusa-core-utils": "^1.0.0",
"medusa-interfaces": "^1.0.0",
"mongoose": "^5.8.0", "mongoose": "^5.8.0",
"morgan": "^1.9.1", "morgan": "^1.9.1",
"passport": "^0.4.0", "passport": "^0.4.0",

View File

@@ -1,13 +1,11 @@
import glob from "glob" import glob from "glob"
import { BaseModel, BaseService, PaymentService } from "medusa-interfaces"
import _ from "lodash" import _ from "lodash"
import path from "path" import path from "path"
import fs from "fs" import fs from "fs"
import { asFunction } from "awilix" import { asFunction } from "awilix"
import { sync as existsSync } from "fs-exists-cached" import { sync as existsSync } from "fs-exists-cached"
import { plugins } from "../../medusa-config.js" 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 * Registers all services in the services directory

View File

@@ -1,11 +1,12 @@
/******************************************************************************* /*******************************************************************************
* models/product-variant.js
* *
******************************************************************************/ ******************************************************************************/
import mongoose from "mongoose" import mongoose from "mongoose"
import { BaseModel } from "../interfaces" import { BaseModel } from "medusa-interfaces"
import LineItemSchema from "./schemas/line-item" import LineItemSchema from "./schemas/line-item"
import PaymentMethodSchema from "./schemas/payment-method"
import ShippingMethodSchema from "./schemas/shipping-method"
import AddressSchema from "./schemas/address" import AddressSchema from "./schemas/address"
class CartModel extends BaseModel { class CartModel extends BaseModel {
@@ -13,12 +14,15 @@ class CartModel extends BaseModel {
static schema = { static schema = {
email: { type: String }, email: { type: String },
billingAddress: { type: AddressSchema }, billing_address: { type: AddressSchema },
shippingAddress: { type: AddressSchema }, shipping_address: { type: AddressSchema },
items: { type: [LinetItemSchema], default: [] }, items: { type: [LineItemSchema], default: [] },
region: { type: String, required: true }, region: { type: String, required: true },
discounts: { type: [String], default: true }, discounts: { type: [String], default: [] },
customer_id: { type: String }, customer_id: { type: String },
payment_method: { type: PaymentMethodSchema },
shipping_methods: { type: [ShippingMethodSchema] },
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
} }
} }

View 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

View 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

View File

@@ -3,7 +3,7 @@
* *
******************************************************************************/ ******************************************************************************/
import mongoose from "mongoose" import mongoose from "mongoose"
import { BaseModel } from "../interfaces" import { BaseModel } from "medusa-interfaces"
import MoneyAmountSchema from "./schemas/money-amount" import MoneyAmountSchema from "./schemas/money-amount"
import OptionValueSchema from "./schemas/option-value" import OptionValueSchema from "./schemas/option-value"

View File

@@ -3,7 +3,7 @@
* *
******************************************************************************/ ******************************************************************************/
import mongoose from "mongoose" import mongoose from "mongoose"
import { BaseModel } from "../interfaces" import { BaseModel } from "medusa-interfaces"
import OptionSchema from "./schemas/option" import OptionSchema from "./schemas/option"

View File

@@ -11,6 +11,7 @@ export default new mongoose.Schema({
// mongoose doesn't allow multi-type validation but this field allows both // mongoose doesn't allow multi-type validation but this field allows both
// an object containing: // an object containing:
// { // {
// unit_price: (MoneyAmount),
// variant: (ProductVariantSchema), // variant: (ProductVariantSchema),
// product: (ProductSchema) // product: (ProductSchema)
// } // }
@@ -18,11 +19,17 @@ export default new mongoose.Schema({
// and and array containing: // and and array containing:
// [ // [
// { // {
// unit_price: (MoneyAmount),
// variant: (ProductVariantSchema), // variant: (ProductVariantSchema),
// product: (ProductSchema) // product: (ProductSchema)
// } // }
// ] // ]
// validation is done in the cart service. // 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 }, content: { type: mongoose.Schema.Types.Mixed, required: true },
quantity: { type: Number, required: true }, quantity: { type: Number, required: true },
metadata: { type: mongoose.Schema.Types.Mixed, default: {} }, metadata: { type: mongoose.Schema.Types.Mixed, default: {} },

View 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: {} },
})

View 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: {} },
})

View File

@@ -2,7 +2,7 @@
* models/user.js * models/user.js
* *
******************************************************************************/ ******************************************************************************/
import { BaseModel } from "../interfaces" import { BaseModel } from "medusa-interfaces"
class UserModel extends BaseModel { class UserModel extends BaseModel {
static modelName = "User" static modelName = "User"

View File

@@ -1,5 +1,5 @@
import bcrypt from "bcrypt" import bcrypt from "bcrypt"
import { BaseService } from "../interfaces" import { BaseService } from "medusa-interfaces"
/** /**
* Can authenticate a user based on email password combination * Can authenticate a user based on email password combination

View File

@@ -1,7 +1,7 @@
import mongoose from "mongoose" import mongoose from "mongoose"
import _ from "lodash" import _ from "lodash"
import { Validator, MedusaError } from "medusa-core-utils" import { Validator, MedusaError } from "medusa-core-utils"
import { BaseService } from "../interfaces" import { BaseService } from "medusa-interfaces"
/** /**
* Provides layer to manipulate carts. * Provides layer to manipulate carts.

View File

@@ -1,5 +1,5 @@
import _ from "lodash" import _ from "lodash"
import { BaseService } from "../interfaces" import { BaseService } from "medusa-interfaces"
import { Validator, MedusaError } from "medusa-core-utils" import { Validator, MedusaError } from "medusa-core-utils"
/** /**

View File

@@ -1,7 +1,7 @@
import mongoose from "mongoose" import mongoose from "mongoose"
import _ from "lodash" import _ from "lodash"
import { Validator, MedusaError } from "medusa-core-utils" import { Validator, MedusaError } from "medusa-core-utils"
import { BaseService } from "../interfaces" import { BaseService } from "medusa-interfaces"
/** /**
* Provides layer to manipulate products. * Provides layer to manipulate products.