Feat: Medusa react price list (#1258)

* export everything from price lists in core

* medusa-js price list

* feat: add product list for price lists

* feat: add product list for price lists

* add price list to admin module

* add price list hooks initial

* refactor: product list controller

* fix: add integration test for price list products

* update types

* add tests for price lists

* update medusa react tests

* update update request for price lists

* Apply suggestions from code review

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>

* rename methods

* pr feedback

* list products from price list

* fix errors after merge

* update medusa react with medusa-js method name changes

* redo changes

* update hook names

* fix: routes in msw handler

Co-authored-by: Sebastian Rindom <skrindom@gmail.com>
Co-authored-by: Zakaria El Asri <zakaria.elas@gmail.com>
This commit is contained in:
Philip Korsholm
2022-04-03 20:48:49 +02:00
committed by GitHub
parent fb33dbaca3
commit b164977a19
24 changed files with 838 additions and 276 deletions

View File

@@ -24,7 +24,7 @@ export default () => {
router.get("/admin/hello", (req, res) => {
res.json({
message: "Welcome to Your Store!"
message: "Welcome to Your Store!",
})
})
@@ -53,8 +53,8 @@ Then, create an object that will hold the CORS configurations:
```js
const corsOptions = {
origin: projectConfig.admin_cors.split(","),
credentials: true,
origin: projectConfig.admin_cors.split(","),
credentials: true,
}
```
@@ -64,7 +64,7 @@ Finally, for each route you add, create an `OPTIONS` request:
router.options("/admin/hello", cors(corsOptions))
router.get("/admin/hello", (req, res) => {
//...
});
})
```
## Multiple Endpoints
@@ -76,13 +76,13 @@ You can add more than one endpoints in `src/api/index.js`:
```js
router.get("/admin/hello", (req, res) => {
res.json({
message: "Welcome to Your Store!"
message: "Welcome to Your Store!",
})
})
router.get("/admin/bye", (req, res) => {
res.json({
message: "Come back again!"
message: "Come back again!",
})
})
```
@@ -97,7 +97,7 @@ To do that with the previous example, first, create the file `src/api/hello.js`
export default (router) => {
router.get("/admin/hello", (req, res) => {
res.json({
message: "Welcome to Your Store!"
message: "Welcome to Your Store!",
})
})
}
@@ -111,7 +111,7 @@ Next, create the file `src/api/bye.js` with the following content:
export default (router) => {
router.get("/admin/bye", (req, res) => {
res.json({
message: "Come back again!"
message: "Come back again!",
})
})
}
@@ -148,17 +148,15 @@ You can retrieve any registered service in your endpoint using `req.scope.resolv
Heres an example of an endpoint that retrieves the count of products in your store:
```js
router.get('/admin/products/count', (req, res) => {
const productService = req.scope.resolve('productService')
router.get("/admin/products/count", (req, res) => {
const productService = req.scope.resolve("productService")
productService
.count()
.then((count) => {
res.json({
count
})
})
productService.count().then((count) => {
res.json({
count,
})
})
})
```
The `productService` has a `count` method that returns a Promise. This Promise resolves to the count of the products. You return a JSON of the product count.
@@ -170,13 +168,13 @@ Protected routes are routes that should be accessible by logged-in users only.
To make a route protected, first, import the `authenticate` middleware:
```js
import authenticate from '@medusajs/medusa/dist/api/middlewares/authenticate'
import authenticate from "@medusajs/medusa/dist/api/middlewares/authenticate"
```
Then, add the middleware to your route:
```js
router.get('/store/products/count', authenticate(), (req, res) => {
router.get("/store/products/count", authenticate(), (req, res) => {
//...
})
```