Feat(admin-next, core-flows, link-modules, medusa, types): Inventory end to end flows (#7020)
* add reservation endpoints * add changeset * initial * add reservations table * add edit-item modal * udpate inventory item attributes * manage locations skeleton * add combi batch endpoint * cleanup * fix manage locations * add adjust inventory * prep for pr * update versions * fix for pr * fix for pr * cleanup * Update packages/core-flows/src/inventory/workflows/bulk-create-delete-levels.ts Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> * Update packages/core-flows/src/inventory/steps/delete-levels-by-item-and-location.ts Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com> * rm wack import * fix build --------- Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
co-authored by
Carlos R. L. Rodrigues
parent
276278cbe7
commit
ab7ff64c4a
+55
@@ -0,0 +1,55 @@
|
||||
import {
|
||||
AdminPostInventoryItemsItemLocationLevelsBatchReq,
|
||||
AdminPostInventoryItemsItemLocationLevelsReq,
|
||||
} from "../../../../validators"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "../../../../../../../types/routing"
|
||||
|
||||
import { bulkCreateDeleteLevelsWorkflow } from "@medusajs/core-flows"
|
||||
import { defaultAdminInventoryItemFields } from "../../../../query-config"
|
||||
|
||||
export const POST = async (
|
||||
req: MedusaRequest<AdminPostInventoryItemsItemLocationLevelsBatchReq>,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const { id } = req.params
|
||||
|
||||
const remoteQuery = req.scope.resolve(ContainerRegistrationKeys.REMOTE_QUERY)
|
||||
|
||||
const workflow = bulkCreateDeleteLevelsWorkflow(req.scope)
|
||||
const { errors } = await workflow.run({
|
||||
input: {
|
||||
deletes: req.validatedBody.deletes.map((location_id) => ({
|
||||
location_id,
|
||||
inventory_item_id: id,
|
||||
})),
|
||||
creates: req.validatedBody.creates.map((c) => ({
|
||||
...c,
|
||||
inventory_item_id: id,
|
||||
})),
|
||||
},
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
if (Array.isArray(errors) && errors[0]) {
|
||||
throw errors[0].error
|
||||
}
|
||||
|
||||
const itemQuery = remoteQueryObjectFromString({
|
||||
entryPoint: "inventory_items",
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: defaultAdminInventoryItemFields,
|
||||
})
|
||||
|
||||
const [inventory_item] = await remoteQuery(itemQuery)
|
||||
|
||||
res.status(200).json({ inventory_item })
|
||||
}
|
||||
@@ -54,9 +54,7 @@ export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
entryPoint: "inventory_levels",
|
||||
variables: {
|
||||
filters: req.filterableFields,
|
||||
order: req.listConfig.order,
|
||||
skip: req.listConfig.skip,
|
||||
take: req.listConfig.take,
|
||||
...req.remoteQueryConfig.pagination,
|
||||
},
|
||||
fields: req.remoteQueryConfig.fields,
|
||||
})
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
AdminGetInventoryItemsParams,
|
||||
AdminPostInventoryItemsInventoryItemParams,
|
||||
AdminPostInventoryItemsInventoryItemReq,
|
||||
AdminPostInventoryItemsItemLocationLevelsBatchReq,
|
||||
AdminPostInventoryItemsItemLocationLevelsLevelParams,
|
||||
AdminPostInventoryItemsItemLocationLevelsLevelReq,
|
||||
AdminPostInventoryItemsItemLocationLevelsReq,
|
||||
@@ -53,6 +54,13 @@ export const adminInventoryRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/inventory-items/:id/location-levels/batch/combi",
|
||||
middlewares: [
|
||||
transformBody(AdminPostInventoryItemsItemLocationLevelsBatchReq),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["GET"],
|
||||
matcher: "/admin/inventory-items/:id/location-levels",
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { InventoryNext } from "@medusajs/types"
|
||||
import { defaultAdminProductsVariantFields } from "../products/query-config"
|
||||
|
||||
// eslint-disable-next-line max-len
|
||||
export const defaultAdminLocationLevelFields = [
|
||||
@@ -37,17 +38,18 @@ export const defaultAdminInventoryItemFields = [
|
||||
...defaultAdminLocationLevelFields.map(
|
||||
(field) => `location_levels.${field.toString()}`
|
||||
),
|
||||
...defaultAdminProductsVariantFields
|
||||
.filter((field) => !field.startsWith("*"))
|
||||
.map((field) => `variant.${field}`),
|
||||
]
|
||||
|
||||
export const retrieveTransformQueryConfig = {
|
||||
defaults: defaultAdminInventoryItemFields,
|
||||
allowed: defaultAdminInventoryItemFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
export const retrieveLocationLevelsTransformQueryConfig = {
|
||||
defaults: defaultAdminLocationLevelFields,
|
||||
allowed: defaultAdminLocationLevelFields,
|
||||
isList: false,
|
||||
}
|
||||
|
||||
|
||||
@@ -127,13 +127,23 @@ export class AdminPostInventoryItemsItemLocationLevelsReq {
|
||||
location_id: string
|
||||
|
||||
@IsNumber()
|
||||
stocked_quantity: number
|
||||
@IsOptional()
|
||||
stocked_quantity?: number
|
||||
|
||||
@IsOptional()
|
||||
@IsNumber()
|
||||
incoming_quantity?: number
|
||||
}
|
||||
|
||||
export class AdminPostInventoryItemsItemLocationLevelsBatchReq {
|
||||
@ValidateNested({ each: true })
|
||||
@Type(() => AdminPostInventoryItemsItemLocationLevelsReq)
|
||||
creates: AdminPostInventoryItemsItemLocationLevelsReq[]
|
||||
|
||||
@IsString({ each: true })
|
||||
deletes: string[]
|
||||
}
|
||||
|
||||
// eslint-disable-next-line
|
||||
export class AdminPostInventoryItemsItemLocationLevelsParams extends FindParams {}
|
||||
|
||||
@@ -259,7 +269,13 @@ export class AdminPostInventoryItemsReq {
|
||||
metadata?: Record<string, unknown>
|
||||
}
|
||||
|
||||
export class AdminGetInventoryItemsItemLocationLevelsParams extends FindParams {
|
||||
// eslint-disable-next-line max-len
|
||||
export class AdminGetInventoryItemsItemLocationLevelsParams extends extendedFindParamsMixin(
|
||||
{
|
||||
limit: 50,
|
||||
offset: 0,
|
||||
}
|
||||
) {
|
||||
/**
|
||||
* Location IDs to filter location levels.
|
||||
*/
|
||||
|
||||
@@ -70,6 +70,7 @@ export const config: MiddlewaresConfig = {
|
||||
...adminProductTypeRoutesMiddlewares,
|
||||
...adminUploadRoutesMiddlewares,
|
||||
...adminFulfillmentSetsRoutesMiddlewares,
|
||||
...adminReservationRoutesMiddlewares,
|
||||
...adminProductCategoryRoutesMiddlewares,
|
||||
...adminReservationRoutesMiddlewares,
|
||||
...adminShippingProfilesMiddlewares,
|
||||
|
||||
Reference in New Issue
Block a user