adds wishlist plugin

This commit is contained in:
Sebastian Rindom
2020-07-20 13:04:29 +02:00
parent 3710f7f80a
commit 0b8f1a5c31
15 changed files with 5776 additions and 4 deletions
@@ -3,8 +3,17 @@ import middlewares from "../../../middlewares"
const route = Router()
export default app => {
export default (app, container) => {
const middlewareService = container.resolve("middlewareService")
app.use("/customers", route)
route.param("id", middlewares.wrap(require("./authorize-customer").default))
// Inject plugin routes
const routers = middlewareService.getRouters("store/customers")
for (const router of routers) {
route.use("/", router)
}
route.post("/", middlewares.wrap(require("./create-customer").default))
@@ -21,8 +30,6 @@ export default app => {
// Authenticated endpoints
route.use(middlewares.authenticate())
route.param("id", middlewares.wrap(require("./authorize-customer").default))
route.get("/:id", middlewares.wrap(require("./get-customer").default))
route.post("/:id", middlewares.wrap(require("./update-customer").default))
@@ -27,7 +27,7 @@ export default (app, container, config) => {
route.use(middlewares.authenticateCustomer())
authRoutes(route)
customerRoutes(route)
customerRoutes(route, container)
productRoutes(route)
orderRoutes(route)
cartRoutes(route)
+24
View File
@@ -52,6 +52,7 @@ export default ({ rootDirectory, container, app }) => {
registerServices(pluginDetails, container)
registerMedusaApi(pluginDetails, container)
registerApi(pluginDetails, app)
registerCoreRouters(pluginDetails, container)
registerSubscribers(pluginDetails, container)
})
}
@@ -84,6 +85,29 @@ function registerMedusaMiddleware(pluginDetails, container) {
}
}
function registerCoreRouters(pluginDetails, container) {
const middlewareService = container.resolve("middlewareService")
const { resolve } = pluginDetails
const adminFiles = glob.sync(`${resolve}/api/admin/[!__]*.js`, {})
const storeFiles = glob.sync(`${resolve}/api/store/[!__]*.js`, {})
adminFiles.forEach(fn => {
const descriptor = fn.split(".")[0]
const splat = descriptor.split("/")
const path = `${splat[splat.length - 2]}/${splat[splat.length - 1]}`
const loaded = require(fn).default
middlewareService.addRouter(path, loaded())
})
storeFiles.forEach(fn => {
const descriptor = fn.split(".")[0]
const splat = descriptor.split("/")
const path = `${splat[splat.length - 2]}/${splat[splat.length - 1]}`
const loaded = require(fn).default
middlewareService.addRouter(path, loaded())
})
}
/**
* Registers the plugin's api routes.
*/
@@ -7,6 +7,17 @@ class MiddlewareService {
constructor(container) {
this.postAuthentication_ = []
this.preAuthentication_ = []
this.routers = {}
}
addRouter(path, router) {
const existing = this.routers[path] || []
this.routers[path] = [...existing, router]
}
getRouters(path) {
const routers = this.routers[path] || []
return routers
}
/**