Adds Middleware API (#40)
* Adds test project * Adds e2e for end-2-end tests * Update gitignore * Update loaders * Creates test project * v0.1.27 * Upgrade * dependency fixes * Load project plugins in the plugin loader * Issue with instanceof * Fixes versioning issues * Adds medusa middleware api * Adds documentation * Fixes tests
This commit is contained in:
1 parent
964e26e310
commit
516bc7675d
46 files changed
+10163
-977
No files matched your search
@@ -0,0 +1,17 @@
|
||||
import { Router } from "express"
|
||||
|
||||
export default () => {
|
||||
const app = Router()
|
||||
|
||||
app.get("/project-root", async (req, res, next) => {
|
||||
try {
|
||||
const testService = req.scope.resolve("testService")
|
||||
const newHi = await testService.sayHi()
|
||||
res.status(200).json(newHi)
|
||||
} catch (e) {
|
||||
next(e)
|
||||
}
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import mongoose from "mongoose"
|
||||
import { BaseModel } from "medusa-interfaces"
|
||||
|
||||
class TestModel extends BaseModel {
|
||||
static modelName = "test"
|
||||
|
||||
static schema = {
|
||||
title: { type: String, required: true },
|
||||
}
|
||||
}
|
||||
|
||||
export default TestModel
|
||||
@@ -0,0 +1,16 @@
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
|
||||
class TestService extends BaseService {
|
||||
constructor({ testModel }) {
|
||||
super()
|
||||
|
||||
this.testModel_ = testModel
|
||||
}
|
||||
|
||||
async sayHi() {
|
||||
const res = await this.testModel_.create({ title: "hi" })
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
export default TestService
|
||||
Reference in new issue
Block a user