feat(medusa-js, medusa-react, medusa): Prepare API for admin implementations (#3110)

********What********
Add `joinSalesChannels util to stock locations

Add the following endpoints to medusa-react
- inventory items
    - mutations
        - update
        - delete
        - update location level
        - delete location level
        - create location level
    - queries
        - list inventory items
        - get inventory item
        - list location levels
- Stock locations
    - mutations
        - create stock location
        - update stock location
        - delete stock location
    - queries
        - list stock locations
        - get stock locatoin
- Variants
    - queries
        - get inventory
- Reservations
    - mutations
        - create reservation
        - update reservation
        - delete reservation
    - queries
        - list reservations
        - get reservation
- sales channels 
  - mutations
    - associate location with sc
    - remove location association

**Why**
- Update clients to reflect new api endpoints in the core with inventory modules

Co-authored-by: Philip Korsholm <88927411+pKorsholm@users.noreply.github.com>
This commit is contained in:
Rares Stefan
2023-02-16 08:49:48 +00:00
committed by GitHub
co-authored by Philip Korsholm
parent 121b42acfe
commit 12d304307a
48 changed files with 1756 additions and 57 deletions
@@ -353,6 +353,61 @@ export const adminHandlers = [
}
),
rest.get("/admin/reservations/", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
reservations: fixtures.list("reservation"),
})
)
}),
rest.post("/admin/reservations/", (req, res, ctx) => {
const body = req.body as Record<string, any>
return res(
ctx.status(200),
ctx.json({
reservation: {
...fixtures.get("reservation"),
...body,
},
})
)
}),
rest.get("/admin/reservations/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
reservation: { ...fixtures.get("reservation"), id: req.params.id },
})
)
}),
rest.post("/admin/reservations/:id", (req, res, ctx) => {
const body = req.body as Record<string, any>
return res(
ctx.status(200),
ctx.json({
reservation: {
...fixtures.get("reservation"),
...body,
id: req.params.id,
},
})
)
}),
rest.delete("/admin/reservations/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
id: req.params.id,
object: "reservation",
deleted: true,
})
)
}),
rest.post("/admin/return-reasons/", (req, res, ctx) => {
const body = req.body as Record<string, any>
return res(
@@ -465,6 +520,61 @@ export const adminHandlers = [
)
}),
rest.get("/admin/stock-locations", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
stock_locations: fixtures.list("stock_location"),
})
)
}),
rest.post("/admin/stock-locations", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
stock_location: {
...fixtures.get("stock_location"),
...(req.body as any),
},
})
)
}),
rest.get("/admin/stock-locations/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
stock_location: {
...fixtures.get("stock_location"),
id: req.params.id,
},
})
)
}),
rest.post("/admin/stock-locations/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
stock_location: {
...fixtures.get("stock_location"),
...(req.body as any),
id: req.params.id,
},
})
)
}),
rest.delete("/admin/stock-locations/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
id: req.params.id,
object: "stock_location",
deleted: true,
})
)
}),
rest.get("/admin/notifications/", (req, res, ctx) => {
return res(
ctx.status(200),
@@ -487,6 +597,112 @@ export const adminHandlers = [
)
}),
// inventory
rest.get("/admin/inventory-items", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
inventory_items: fixtures.list("inventory_item"),
})
)
}),
rest.get("/admin/inventory-items/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
inventory_item: fixtures.get("inventory_item"),
})
)
}),
rest.post("/admin/inventory-items/:id", (req, res, ctx) => {
const body = req.body as Record<string, any>
return res(
ctx.status(200),
ctx.json({
inventory_item: {
...fixtures.get("inventory_item"),
...body,
id: req.params.id,
},
})
)
}),
rest.delete("/admin/inventory-items/:id", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
id: req.params.id,
object: "inventory_item",
deleted: true,
})
)
}),
rest.get("/admin/inventory-items/:id/location-levels", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
inventory_item: {
...fixtures.get("inventory_item"),
id: req.params.id,
},
})
)
}),
rest.post("/admin/inventory-items/:id/location-levels", (req, res, ctx) => {
const body = req.body as Record<string, any>
const { location_levels } = fixtures.get("inventory_item")
return res(
ctx.status(200),
ctx.json({
inventory_item: {
...fixtures.get("inventory_item"),
id: req.params.id,
location_levels: [...location_levels, { ...body, id: "2" }],
},
})
)
}),
rest.post(
"/admin/inventory-items/:id/location-levels/:location_id",
(req, res, ctx) => {
const body = req.body as Record<string, any>
const inventoryItem = fixtures.get("inventory_item")
const locationlevel = { ...inventoryItem.location_levels[0], ...body }
return res(
ctx.status(200),
ctx.json({
inventory_item: {
...fixtures.get("inventory_item"),
id: req.params.id,
location_levels: [locationlevel],
},
})
)
}
),
rest.delete(
"/admin/inventory-items/:id/location-levels/:location_id",
(req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
inventory_item: {
...fixtures.get("inventory_item"),
id: req.params.id,
location_levels: [],
},
})
)
}
),
rest.get("/admin/invites", (req, res, ctx) => {
return res(
ctx.status(200),
@@ -1189,6 +1405,24 @@ export const adminHandlers = [
)
}),
rest.get("/admin/variants/:id/inventory", (req, res, ctx) => {
return res(
ctx.status(200),
ctx.json({
variant: {
...fixtures.get("product_variant"),
sales_channel_availability: [
{
channel_name: "default channel",
channel_id: "1",
available_quantity: 10,
},
],
},
})
)
}),
rest.get("/admin/users/:id", (req, res, ctx) => {
return res(
ctx.status(200),