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:
6
.changeset/yellow-moose-laugh.md
Normal file
6
.changeset/yellow-moose-laugh.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"@medusajs/core-flows": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
feat(medusa, core-flows): add retrieve stock location endpoint to api-v2
|
||||
@@ -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 () => {
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
@@ -137,3 +137,5 @@ export class AdminPostStockLocationsReq {
|
||||
}
|
||||
|
||||
export class AdminPostStockLocationsParams extends FindParams {}
|
||||
|
||||
export class AdminGetStockLocationsLocationParams extends FindParams {}
|
||||
|
||||
Reference in New Issue
Block a user