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:
@@ -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
|
||||
Here’s 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) => {
|
||||
//...
|
||||
})
|
||||
```
|
||||
|
||||
@@ -24,7 +24,7 @@ export default () => {
|
||||
|
||||
router.get("/store/hello", (req, res) => {
|
||||
res.json({
|
||||
message: "Welcome to My Store!"
|
||||
message: "Welcome to My Store!",
|
||||
})
|
||||
})
|
||||
|
||||
@@ -47,13 +47,13 @@ You can add more than one endpoints in `src/api/index.js`:
|
||||
```js
|
||||
router.get("/store/hello", (req, res) => {
|
||||
res.json({
|
||||
message: "Welcome to My Store!"
|
||||
message: "Welcome to My Store!",
|
||||
})
|
||||
})
|
||||
|
||||
router.get("/store/bye", (req, res) => {
|
||||
res.json({
|
||||
message: "Come back again!"
|
||||
message: "Come back again!",
|
||||
})
|
||||
})
|
||||
```
|
||||
@@ -68,7 +68,7 @@ To do that with the previous example, first, create the file `src/api/hello.js`
|
||||
export default (router) => {
|
||||
router.get("/store/hello", (req, res) => {
|
||||
res.json({
|
||||
message: "Welcome to My Store!"
|
||||
message: "Welcome to My Store!",
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -82,7 +82,7 @@ Next, create the file `src/api/bye.js` with the following content:
|
||||
export default (router) => {
|
||||
router.get("/store/bye", (req, res) => {
|
||||
res.json({
|
||||
message: "Come back again!"
|
||||
message: "Come back again!",
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -119,17 +119,15 @@ You can retrieve any registered service in your endpoint using `req.scope.resolv
|
||||
Here’s an example of an endpoint that retrieves the count of products in your store:
|
||||
|
||||
```js
|
||||
router.get('/store/products/count', (req, res) => {
|
||||
const productService = req.scope.resolve('productService')
|
||||
router.get("/store/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.
|
||||
@@ -141,13 +139,13 @@ Protected routes are routes that should be accessible by logged-in customers onl
|
||||
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:
|
||||
|
||||
```jsx
|
||||
router.get('/store/products/count', authenticate(), (req, res) => {
|
||||
router.get("/store/products/count", authenticate(), (req, res) => {
|
||||
//...
|
||||
})
|
||||
```
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
---
|
||||
|
||||
title: Create a Service
|
||||
|
||||
---
|
||||
|
||||
# Create a Service
|
||||
@@ -31,7 +29,7 @@ To create a service, you should create a JavaScript file in `src/services` to ho
|
||||
For example, if you want to create a service `helloService`, create the file `hello.js` in `src/services` with the following content:
|
||||
|
||||
```js
|
||||
import { BaseService } from "medusa-interfaces";
|
||||
import { BaseService } from "medusa-interfaces"
|
||||
|
||||
class HelloService extends BaseService {
|
||||
getMessage() {
|
||||
@@ -39,7 +37,7 @@ class HelloService extends BaseService {
|
||||
}
|
||||
}
|
||||
|
||||
export default HelloService;
|
||||
export default HelloService
|
||||
```
|
||||
|
||||
## Service Constructor
|
||||
@@ -85,10 +83,10 @@ constructor({ helloService }) {
|
||||
To use your custom service in an endpoint, you can use `req.scope.resolve` passing it the service’s registration name:
|
||||
|
||||
```js
|
||||
const helloService = req.scope.resolve('helloService');
|
||||
const helloService = req.scope.resolve("helloService")
|
||||
|
||||
res.json({
|
||||
message: helloService.getMessage()
|
||||
message: helloService.getMessage(),
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user