-
Notifications
You must be signed in to change notification settings - Fork 250
Mm2 1416 vendor inventory UI issue for toast #453
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
itariv
wants to merge
2
commits into
testing
Choose a base branch
from
MM2-1416-vendor-inventory-ui-issue-for-toast
base: testing
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...odules/b2c-core/src/api/admin/inventory-items/[id]/location-levels/[location_id]/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| import { | ||
| ContainerRegistrationKeys, | ||
| MedusaError, | ||
| } from "@medusajs/framework/utils"; | ||
| import { MedusaRequest, MedusaResponse } from "@medusajs/framework/http"; | ||
|
|
||
| import { deleteInventoryLevelsWorkflow } from "@medusajs/core-flows"; | ||
| import { HttpTypes } from "@medusajs/framework/types"; | ||
| import { refetchInventoryItem } from "@medusajs/medusa/api/admin/inventory-items/helpers"; | ||
|
|
||
| // Overridden admin default delete inventory level route to force delete the inventory level with stocked items at the locations. | ||
|
|
||
| export const DELETE = async ( | ||
| req: MedusaRequest, | ||
| res: MedusaResponse<HttpTypes.AdminInventoryLevelDeleteResponse> | ||
| ) => { | ||
| const { id, location_id } = req.params; | ||
|
|
||
| const query = req.scope.resolve(ContainerRegistrationKeys.QUERY); | ||
|
|
||
| const result = await query.graph({ | ||
| entity: "inventory_level", | ||
| filters: { inventory_item_id: id, location_id }, | ||
| fields: ["id", "reserved_quantity"], | ||
| }); | ||
|
|
||
| if (!result.data.length) { | ||
| throw new MedusaError( | ||
| MedusaError.Types.NOT_FOUND, | ||
| `Inventory Level for Item ${id} at Location ${location_id} not found` | ||
| ); | ||
| } | ||
|
|
||
| const { id: levelId, reserved_quantity: reservedQuantity } = result.data[0]; | ||
|
|
||
| if (reservedQuantity > 0) { | ||
| throw new MedusaError( | ||
| MedusaError.Types.NOT_ALLOWED, | ||
| `Cannot remove Inventory Level ${id} at Location ${location_id} because there are reservations at location` | ||
| ); | ||
| } | ||
|
|
||
| const deleteInventoryLevelWorkflow = deleteInventoryLevelsWorkflow(req.scope); | ||
|
|
||
| await deleteInventoryLevelWorkflow.run({ | ||
| input: { | ||
| id: [levelId], | ||
| force: true, | ||
| }, | ||
| }); | ||
|
|
||
| const inventoryItem = await refetchInventoryItem( | ||
| id, | ||
| req.scope, | ||
| req.queryConfig.fields | ||
| ); | ||
|
|
||
| res.status(200).json({ | ||
| id: levelId, | ||
| object: "inventory-level", | ||
| deleted: true, | ||
| parent: inventoryItem, | ||
| }); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import { AuthenticatedMedusaRequest, MedusaResponse } from '@medusajs/framework' | ||
| import { ContainerRegistrationKeys, Modules } from '@medusajs/framework/utils' | ||
| import { updateInventoryLevelsWorkflow } from '@medusajs/medusa/core-flows' | ||
| import { ContainerRegistrationKeys, Modules, MedusaError } from '@medusajs/framework/utils' | ||
| import { updateInventoryLevelsWorkflow, deleteInventoryLevelsWorkflow } from '@medusajs/medusa/core-flows' | ||
|
|
||
| import { IntermediateEvents } from '@mercurjs/framework' | ||
|
|
||
| import { VendorUpdateInventoryLevelType } from '../../../validators' | ||
| import { VendorInventoryLevelDeleteResponse } from '../../../validators' | ||
| import { refetchInventoryItem } from '@medusajs/medusa/api/admin/inventory-items/helpers' | ||
|
|
||
| /** | ||
| * @oas [post] /vendor/inventory-items/{id}/location-levels/{location_id} | ||
|
|
@@ -128,3 +130,87 @@ export const GET = async ( | |
| location_level | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * @oas [delete] /vendor/inventory-items/{id}/location-levels/{location_id} | ||
| * operationId: "VendorDeleteInventoryLevel" | ||
| * summary: "Delete inventory level" | ||
| * description: "Deletes inventory level of the InventoryItem in the specified location" | ||
| * x-authenticated: true | ||
| * parameters: | ||
| * - in: path | ||
| * name: id | ||
| * required: true | ||
| * description: The ID of the InventoryItem. | ||
| * schema: | ||
| * type: string | ||
| * - in: path | ||
| * name: location_id | ||
| * required: true | ||
| * description: The ID of the Stock Location. | ||
| * schema: | ||
| * type: string | ||
| * responses: | ||
| * "200": | ||
| * description: Inventory level | ||
| * tags: | ||
| * - Vendor Inventory Items | ||
| * security: | ||
| * - api_token: [] | ||
| * - cookie_auth: [] | ||
| */ | ||
|
|
||
| export const DELETE = async ( | ||
| req: AuthenticatedMedusaRequest, | ||
| res: MedusaResponse<VendorInventoryLevelDeleteResponse> | ||
| ) => { | ||
| const { id, location_id } = req.params | ||
|
|
||
| const query = req.scope.resolve(ContainerRegistrationKeys.QUERY) | ||
|
|
||
| const result = await query.graph({ | ||
| entity: "inventory_level", | ||
| filters: { inventory_item_id: id, location_id }, | ||
| fields: ["id", "reserved_quantity"], | ||
| }) | ||
|
|
||
| if (!result.data.length) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap in try catch (not sure if needed) and add to query.graph
|
||
| throw new MedusaError( | ||
| MedusaError.Types.NOT_FOUND, | ||
| `Inventory Level for Item ${id} at Location ${location_id} not found` | ||
| ) | ||
| } | ||
|
|
||
| const { id: levelId, reserved_quantity: reservedQuantity } = result.data[0] | ||
|
|
||
| if (reservedQuantity > 0) { | ||
| throw new MedusaError( | ||
| MedusaError.Types.NOT_ALLOWED, | ||
| `Cannot remove Inventory Level ${id} at Location ${location_id} because there are reservations at location` | ||
| ) | ||
| } | ||
|
|
||
| const deleteInventoryLevelWorkflow = deleteInventoryLevelsWorkflow(req.scope) | ||
|
|
||
| await deleteInventoryLevelWorkflow.run({ | ||
| input: { | ||
| id: [levelId], | ||
| force: true, | ||
| }, | ||
| }) | ||
|
|
||
| const inventoryItem = await refetchInventoryItem( | ||
| id, | ||
| req.scope, | ||
| req.queryConfig.fields | ||
| ) | ||
|
|
||
| res.status(200).json({ | ||
| id: levelId, | ||
| object: "inventory-level", | ||
| deleted: true, | ||
| parent: inventoryItem, | ||
| }) | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wrap in try catch (not sure if needed) and add to query.graph
{ throwIfKeyNotFound: true }