feat(medusa, core-flows): add retrieve stock location endpoint to api-v2 (#6791)

* initial create

* add changeset

* redo changes for stock locatino module'

* add get endpoint

* add changeset

* add exception if location is not found

* remove only

* initial delete stock location

* add changeset

* add changeset

* pr prep

* remote duplicate changeset

* propagate deletion with common step

* move integration tests

---------

Co-authored-by: Riqwan Thamir <rmthamir@gmail.com>
This commit is contained in:
Philip Korsholm
2024-03-25 16:58:23 +01:00
committed by GitHub
parent deab12e27e
commit 20132d7cea
5 changed files with 89 additions and 0 deletions

View File

@@ -0,0 +1,6 @@
---
"@medusajs/core-flows": patch
"@medusajs/medusa": patch
---
feat(medusa, core-flows): add retrieve stock location endpoint to api-v2

View File

@@ -56,6 +56,47 @@ medusaIntegrationTestRunner({
})
})
describe("Get stock location", () => {
let locationId
const location = {
name: "Test Location",
}
beforeEach(async () => {
const createLocationRespones = await api.post(
"/admin/stock-locations",
{
...location,
},
adminHeaders
)
locationId = createLocationRespones.data.stock_location.id
})
it("should get a stock location", async () => {
const response = await api.get(
`/admin/stock-locations/${locationId}`,
adminHeaders
)
expect(response.status).toEqual(200)
expect(response.data.stock_location).toEqual(
expect.objectContaining({ id: locationId, ...location })
)
})
it("should get a stock location", async () => {
let error
await api
.get(`/admin/stock-locations/does-not-exist`, adminHeaders)
.catch((e) => (error = e))
expect(error.response.status).toEqual(404)
expect(error.response.data.message).toEqual(
`Stock location with id: does-not-exist was not found`
)
})
})
describe("Delete stock location", () => {
let stockLocationId
beforeEach(async () => {

View File

@@ -1,7 +1,36 @@
import {
ContainerRegistrationKeys,
remoteQueryObjectFromString,
} from "@medusajs/utils"
import { MedusaRequest, MedusaResponse } from "../../../../types/routing"
import { MedusaError } from "@medusajs/utils"
import { deleteStockLocationsWorkflow } from "@medusajs/core-flows"
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
const { id } = req.params
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
const [stock_location] = await remoteQuery(
remoteQueryObjectFromString({
entryPoint: "stock_locations",
variables: {
id,
},
fields: req.remoteQueryConfig.fields,
})
)
if (!stock_location) {
throw new MedusaError(
MedusaError.Types.NOT_FOUND,
`Stock location with id: ${id} was not found`
)
}
res.status(200).json({ stock_location })
}
export const DELETE = async (req: MedusaRequest, res: MedusaResponse) => {
const { id } = req.params

View File

@@ -1,6 +1,7 @@
import * as QueryConfig from "./query-config"
import {
AdminGetStockLocationsLocationParams,
AdminPostStockLocationsParams,
AdminPostStockLocationsReq,
} from "./validators"
@@ -26,4 +27,14 @@ export const adminStockLocationRoutesMiddlewares: MiddlewareRoute[] = [
),
],
},
{
method: ["GET"],
matcher: "/admin/stock-locations/:id",
middlewares: [
transformQuery(
AdminGetStockLocationsLocationParams,
QueryConfig.retrieveTransformQueryConfig
),
],
},
]

View File

@@ -137,3 +137,5 @@ export class AdminPostStockLocationsReq {
}
export class AdminPostStockLocationsParams extends FindParams {}
export class AdminGetStockLocationsLocationParams extends FindParams {}