feat: add a line item to an order edit (#2243)

**What**
- Implement adding a line item to order (edit)

**How**
- _by implementing the following "flow"_
  - generate a line item
  - computing line item adjustments for that line item
  - creating tax lines
  - creating a change record

**Testing**
- **_integration tests_**
  - check if line item and order item change objects are created (with correct tax lines)
  - line item adjustments are generated if
    - fixed discount is applied to cart
    - percentage discount is applied
- **_unit tests_** 
  - ensure that methods from Inventory, LineItem, LineItemAdjustment etc. services are called 

---

RESOLVES CORE-495
This commit is contained in:
Frane Polić
2022-09-28 11:51:13 +00:00
committed by GitHub
parent 474e97252c
commit 884f36e8a8
19 changed files with 679 additions and 80 deletions
@@ -2,9 +2,10 @@ import {
AdminOrderEditDeleteRes,
AdminOrderEditItemChangeDeleteRes,
AdminOrderEditsRes,
AdminPostOrderEditsEditLineItemsLineItemReq,
AdminPostOrderEditsOrderEditReq,
AdminPostOrderEditsReq,
AdminPostOrderEditsEditLineItemsReq,
AdminPostOrderEditsEditLineItemsLineItemReq,
} from "@medusajs/medusa"
import { ResponsePromise } from "../../typings"
import BaseResource from "../base"
@@ -43,6 +44,15 @@ class AdminOrderEditsResource extends BaseResource {
return this.client.request("DELETE", path, undefined, {}, customHeaders)
}
addLineItem(
id: string,
payload: AdminPostOrderEditsEditLineItemsReq,
customHeaders: Record<string, any> = {}
): ResponsePromise<AdminOrderEditsRes> {
const path = `/admin/order-edits/${id}/items`
return this.client.request("POST", path, payload, {}, customHeaders)
}
deleteItemChange(
orderEditId: string,
itemChangeId: string,