Feat: draft order api (#6797)

This commit is contained in:
Carlos R. L. Rodrigues
2024-04-06 16:35:10 +02:00
committed by GitHub
parent 883a75c4f3
commit df0751f122
63 changed files with 2179 additions and 1424 deletions
@@ -378,7 +378,7 @@ moduleIntegrationTestRunner({
})
})
describe("addLineItems", () => {
describe("createLineItems", () => {
it("should add a line item to order succesfully", async () => {
const [createdOrder] = await service.create([
{
@@ -386,7 +386,7 @@ moduleIntegrationTestRunner({
},
])
await service.addLineItems(createdOrder.id, [
await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -415,7 +415,7 @@ moduleIntegrationTestRunner({
},
])
await service.addLineItems([
await service.createLineItems([
{
quantity: 1,
unit_price: 100,
@@ -466,7 +466,7 @@ moduleIntegrationTestRunner({
},
])
const items = await service.addLineItems([
const items = await service.createLineItems([
{
order_id: eurOrder.id,
quantity: 1,
@@ -502,7 +502,7 @@ moduleIntegrationTestRunner({
it("should throw if order does not exist", async () => {
const error = await service
.addLineItems("foo", [
.createLineItems("foo", [
{
quantity: 1,
unit_price: 100,
@@ -523,7 +523,7 @@ moduleIntegrationTestRunner({
])
const error = await service
.addLineItems(createdOrder.id, [
.createLineItems(createdOrder.id, [
{
unit_price: 10,
title: "test",
@@ -544,7 +544,7 @@ moduleIntegrationTestRunner({
])
const error = await service
.addLineItems([
.createLineItems([
{
order_id: createdOrder.id,
unit_price: 10,
@@ -567,7 +567,7 @@ moduleIntegrationTestRunner({
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -595,7 +595,7 @@ moduleIntegrationTestRunner({
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -620,7 +620,7 @@ moduleIntegrationTestRunner({
},
])
const items = await service.addLineItems(createdOrder.id, [
const items = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -686,15 +686,15 @@ moduleIntegrationTestRunner({
})
})
describe("removeLineItems", () => {
it("should remove a line item succesfully", async () => {
describe("deleteLineItems", () => {
it("should delete a line item succesfully", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -705,7 +705,7 @@ moduleIntegrationTestRunner({
expect(item.title).toBe("test")
await service.removeLineItems([item.id])
await service.deleteLineItems([item.id])
const order = await service.retrieve(createdOrder.id, {
relations: ["items"],
@@ -714,14 +714,14 @@ moduleIntegrationTestRunner({
expect(order.items?.length).toBe(0)
})
it("should remove multiple line items succesfully", async () => {
it("should delete multiple line items succesfully", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [item, item2] = await service.addLineItems(createdOrder.id, [
const [item, item2] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -734,7 +734,7 @@ moduleIntegrationTestRunner({
},
])
await service.removeLineItems([item.id, item2.id])
await service.deleteLineItems([item.id, item2.id])
const order = await service.retrieve(createdOrder.id, {
relations: ["items"],
@@ -744,7 +744,7 @@ moduleIntegrationTestRunner({
})
})
describe("addShippingMethods", () => {
describe("createShippingMethods", () => {
it("should add a shipping method to order succesfully", async () => {
const [createdOrder] = await service.create([
{
@@ -752,12 +752,15 @@ moduleIntegrationTestRunner({
},
])
const [method] = await service.addShippingMethods(createdOrder.id, [
{
amount: 100,
name: "Test",
},
])
const [method] = await service.createShippingMethods(
createdOrder.id,
[
{
amount: 100,
name: "Test",
},
]
)
const order = await service.retrieve(createdOrder.id, {
relations: ["shipping_methods"],
@@ -779,7 +782,7 @@ moduleIntegrationTestRunner({
},
])
const methods = await service.addShippingMethods([
const methods = await service.createShippingMethods([
{
order_id: eurOrder.id,
amount: 100,
@@ -811,24 +814,27 @@ moduleIntegrationTestRunner({
})
})
describe("removeShippingMethods", () => {
it("should remove a line item succesfully", async () => {
describe("deleteShippingMethods", () => {
it("should delete a line item succesfully", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [method] = await service.addShippingMethods(createdOrder.id, [
{
amount: 100,
name: "test",
},
])
const [method] = await service.createShippingMethods(
createdOrder.id,
[
{
amount: 100,
name: "test",
},
]
)
expect(method.id).not.toBe(null)
await service.removeShippingMethods(method.id)
await service.deleteShippingMethods(method.id)
const order = await service.retrieve(createdOrder.id, {
relations: ["shipping_methods"],
@@ -846,7 +852,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -854,7 +860,7 @@ moduleIntegrationTestRunner({
},
])
const [itemTwo] = await service.addLineItems(createdOrder.id, [
const [itemTwo] = await service.createLineItems(createdOrder.id, [
{
quantity: 2,
unit_price: 200,
@@ -901,7 +907,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -961,14 +967,14 @@ moduleIntegrationTestRunner({
expect(order.items[0].adjustments?.length).toBe(1)
})
it("should remove all line item adjustments for an order", async () => {
it("should delete all line item adjustments for an order", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -1023,7 +1029,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -1086,7 +1092,7 @@ moduleIntegrationTestRunner({
})
})
describe("addLineItemAdjustments", () => {
describe("createLineItemAdjustments", () => {
it("should add line item adjustments for items in an order", async () => {
const [createdOrder] = await service.create([
{
@@ -1094,7 +1100,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -1102,7 +1108,7 @@ moduleIntegrationTestRunner({
},
])
const adjustments = await service.addLineItemAdjustments(
const adjustments = await service.createLineItemAdjustments(
createdOrder.id,
[
{
@@ -1131,14 +1137,14 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
title: "test",
},
])
const [itemTwo] = await service.addLineItems(createdOrder.id, [
const [itemTwo] = await service.createLineItems(createdOrder.id, [
{
quantity: 2,
unit_price: 200,
@@ -1146,7 +1152,7 @@ moduleIntegrationTestRunner({
},
])
const adjustments = await service.addLineItemAdjustments(
const adjustments = await service.createLineItemAdjustments(
createdOrder.id,
[
{
@@ -1188,14 +1194,14 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(orderOne.id, [
const [itemOne] = await service.createLineItems(orderOne.id, [
{
quantity: 1,
unit_price: 100,
title: "test",
},
])
const [itemTwo] = await service.addLineItems(orderTwo.id, [
const [itemTwo] = await service.createLineItems(orderTwo.id, [
{
quantity: 2,
unit_price: 200,
@@ -1203,7 +1209,7 @@ moduleIntegrationTestRunner({
},
])
await service.addLineItemAdjustments([
await service.createLineItemAdjustments([
// item from order one
{
item_id: itemOne.id,
@@ -1255,15 +1261,15 @@ moduleIntegrationTestRunner({
})
})
describe("removeLineItemAdjustments", () => {
it("should remove a line item succesfully", async () => {
describe("deleteLineItemAdjustments", () => {
it("should delete a line item succesfully", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -1271,7 +1277,7 @@ moduleIntegrationTestRunner({
},
])
const [adjustment] = await service.addLineItemAdjustments(
const [adjustment] = await service.createLineItemAdjustments(
createdOrder.id,
[
{
@@ -1283,7 +1289,7 @@ moduleIntegrationTestRunner({
expect(adjustment.item_id).toBe(item.id)
await service.removeLineItemAdjustments(adjustment.id)
await service.deleteLineItemAdjustments(adjustment.id)
const adjustments = await service.listLineItemAdjustments({
item_id: item.id,
@@ -1292,14 +1298,14 @@ moduleIntegrationTestRunner({
expect(adjustments?.length).toBe(0)
})
it("should remove a line item succesfully with selector", async () => {
it("should delete a line item succesfully with selector", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -1307,7 +1313,7 @@ moduleIntegrationTestRunner({
},
])
const [adjustment] = await service.addLineItemAdjustments(
const [adjustment] = await service.createLineItemAdjustments(
createdOrder.id,
[
{
@@ -1319,7 +1325,7 @@ moduleIntegrationTestRunner({
expect(adjustment.item_id).toBe(item.id)
await service.removeLineItemAdjustments({ item_id: item.id })
await service.deleteLineItemAdjustments({ item_id: item.id })
const adjustments = await service.listLineItemAdjustments({
item_id: item.id,
@@ -1337,7 +1343,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1347,7 +1353,7 @@ moduleIntegrationTestRunner({
]
)
const [shippingMethodTwo] = await service.addShippingMethods(
const [shippingMethodTwo] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1396,7 +1402,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1459,14 +1465,14 @@ moduleIntegrationTestRunner({
expect(order.shipping_methods?.[0].adjustments?.length).toBe(1)
})
it("should remove all shipping method adjustments for an order", async () => {
it("should delete all shipping method adjustments for an order", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1523,7 +1529,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1587,7 +1593,7 @@ moduleIntegrationTestRunner({
})
})
describe("addShippingMethodAdjustments", () => {
describe("createShippingMethodAdjustments", () => {
it("should add shipping method adjustments in an order", async () => {
const [createdOrder] = await service.create([
{
@@ -1595,7 +1601,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1605,7 +1611,7 @@ moduleIntegrationTestRunner({
]
)
const adjustments = await service.addShippingMethodAdjustments(
const adjustments = await service.createShippingMethodAdjustments(
createdOrder.id,
[
{
@@ -1634,7 +1640,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1643,7 +1649,7 @@ moduleIntegrationTestRunner({
},
]
)
const [shippingMethodTwo] = await service.addShippingMethods(
const [shippingMethodTwo] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1653,7 +1659,7 @@ moduleIntegrationTestRunner({
]
)
const adjustments = await service.addShippingMethodAdjustments(
const adjustments = await service.createShippingMethodAdjustments(
createdOrder.id,
[
{
@@ -1697,7 +1703,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
orderOne.id,
[
{
@@ -1706,7 +1712,7 @@ moduleIntegrationTestRunner({
},
]
)
const [shippingMethodTwo] = await service.addShippingMethods(
const [shippingMethodTwo] = await service.createShippingMethods(
orderTwo.id,
[
{
@@ -1716,7 +1722,7 @@ moduleIntegrationTestRunner({
]
)
await service.addShippingMethodAdjustments([
await service.createShippingMethodAdjustments([
// item from order one
{
shipping_method_id: shippingMethodOne.id,
@@ -1782,7 +1788,7 @@ moduleIntegrationTestRunner({
},
])
const [shippingMethodOne] = await service.addShippingMethods(
const [shippingMethodOne] = await service.createShippingMethods(
orderOne.id,
[
{
@@ -1793,7 +1799,7 @@ moduleIntegrationTestRunner({
)
const error = await service
.addShippingMethodAdjustments(orderTwo.id, [
.createShippingMethodAdjustments(orderTwo.id, [
{
shipping_method_id: shippingMethodOne.id,
amount: 100,
@@ -1808,22 +1814,25 @@ moduleIntegrationTestRunner({
})
})
describe("removeShippingMethodAdjustments", () => {
it("should remove a shipping method succesfully", async () => {
describe("deleteShippingMethodAdjustments", () => {
it("should delete a shipping method succesfully", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [method] = await service.addShippingMethods(createdOrder.id, [
{
amount: 100,
name: "test",
},
])
const [method] = await service.createShippingMethods(
createdOrder.id,
[
{
amount: 100,
name: "test",
},
]
)
const [adjustment] = await service.addShippingMethodAdjustments(
const [adjustment] = await service.createShippingMethodAdjustments(
createdOrder.id,
[
{
@@ -1836,7 +1845,7 @@ moduleIntegrationTestRunner({
expect(adjustment.shipping_method_id).toBe(method.id)
await service.removeShippingMethodAdjustments(adjustment.id)
await service.deleteShippingMethodAdjustments(adjustment.id)
const adjustments = await service.listShippingMethodAdjustments({
shipping_method_id: method.id,
@@ -1845,14 +1854,14 @@ moduleIntegrationTestRunner({
expect(adjustments?.length).toBe(0)
})
it("should remove a shipping method succesfully with selector", async () => {
it("should delete a shipping method succesfully with selector", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [shippingMethod] = await service.addShippingMethods(
const [shippingMethod] = await service.createShippingMethods(
createdOrder.id,
[
{
@@ -1862,7 +1871,7 @@ moduleIntegrationTestRunner({
]
)
const [adjustment] = await service.addShippingMethodAdjustments(
const [adjustment] = await service.createShippingMethodAdjustments(
createdOrder.id,
[
{
@@ -1875,7 +1884,7 @@ moduleIntegrationTestRunner({
expect(adjustment.shipping_method_id).toBe(shippingMethod.id)
await service.removeShippingMethodAdjustments({
await service.deleteShippingMethodAdjustments({
shipping_method_id: shippingMethod.id,
})
@@ -1895,7 +1904,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -1903,7 +1912,7 @@ moduleIntegrationTestRunner({
},
])
const [itemTwo] = await service.addLineItems(createdOrder.id, [
const [itemTwo] = await service.createLineItems(createdOrder.id, [
{
quantity: 2,
unit_price: 200,
@@ -1947,7 +1956,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2004,14 +2013,14 @@ moduleIntegrationTestRunner({
expect(order.items[0].tax_lines.length).toBe(1)
})
it("should remove all line item tax lines for an order", async () => {
it("should delete all line item tax lines for an order", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2063,7 +2072,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2122,14 +2131,14 @@ moduleIntegrationTestRunner({
expect(order.items[0].tax_lines.length).toBe(1)
})
it("should remove, update, and create line item tax lines for an order", async () => {
it("should delete, update, and create line item tax lines for an order", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2180,7 +2189,7 @@ moduleIntegrationTestRunner({
rate: 25,
code: "TX-2",
},
// remove: should remove the initial tax line for itemOne
// delete: should delete the initial tax line for itemOne
])
const order = await service.retrieve(createdOrder.id, {
@@ -2213,7 +2222,7 @@ moduleIntegrationTestRunner({
})
})
describe("addLineItemAdjustments", () => {
describe("createLineItemAdjustments", () => {
it("should add line item tax lines for items in an order", async () => {
const [createdOrder] = await service.create([
{
@@ -2221,7 +2230,7 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2229,13 +2238,16 @@ moduleIntegrationTestRunner({
},
])
const taxLines = await service.addLineItemTaxLines(createdOrder.id, [
{
item_id: itemOne.id,
rate: 20,
code: "TX",
},
])
const taxLines = await service.createLineItemTaxLines(
createdOrder.id,
[
{
item_id: itemOne.id,
rate: 20,
code: "TX",
},
]
)
expect(taxLines).toEqual(
expect.arrayContaining([
@@ -2255,14 +2267,14 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(createdOrder.id, [
const [itemOne] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
title: "test",
},
])
const [itemTwo] = await service.addLineItems(createdOrder.id, [
const [itemTwo] = await service.createLineItems(createdOrder.id, [
{
quantity: 2,
unit_price: 200,
@@ -2270,18 +2282,21 @@ moduleIntegrationTestRunner({
},
])
const taxLines = await service.addLineItemTaxLines(createdOrder.id, [
{
item_id: itemOne.id,
rate: 20,
code: "TX",
},
{
item_id: itemTwo.id,
rate: 20,
code: "TX",
},
])
const taxLines = await service.createLineItemTaxLines(
createdOrder.id,
[
{
item_id: itemOne.id,
rate: 20,
code: "TX",
},
{
item_id: itemTwo.id,
rate: 20,
code: "TX",
},
]
)
expect(taxLines).toEqual(
expect.arrayContaining([
@@ -2311,14 +2326,14 @@ moduleIntegrationTestRunner({
},
])
const [itemOne] = await service.addLineItems(orderOne.id, [
const [itemOne] = await service.createLineItems(orderOne.id, [
{
quantity: 1,
unit_price: 100,
title: "test",
},
])
const [itemTwo] = await service.addLineItems(orderTwo.id, [
const [itemTwo] = await service.createLineItems(orderTwo.id, [
{
quantity: 2,
unit_price: 200,
@@ -2326,7 +2341,7 @@ moduleIntegrationTestRunner({
},
])
await service.addLineItemTaxLines([
await service.createLineItemTaxLines([
// item from order one
{
item_id: itemOne.id,
@@ -2378,15 +2393,15 @@ moduleIntegrationTestRunner({
})
})
describe("removeLineItemAdjustments", () => {
it("should remove line item tax line succesfully", async () => {
describe("deleteLineItemAdjustments", () => {
it("should delete line item tax line succesfully", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2394,17 +2409,20 @@ moduleIntegrationTestRunner({
},
])
const [taxLine] = await service.addLineItemTaxLines(createdOrder.id, [
{
item_id: item.id,
rate: 20,
code: "TX",
},
])
const [taxLine] = await service.createLineItemTaxLines(
createdOrder.id,
[
{
item_id: item.id,
rate: 20,
code: "TX",
},
]
)
expect(taxLine.item_id).toBe(item.id)
await service.removeLineItemTaxLines(taxLine.id)
await service.deleteLineItemTaxLines(taxLine.id)
const taxLines = await service.listLineItemTaxLines({
item_id: item.id,
@@ -2413,14 +2431,14 @@ moduleIntegrationTestRunner({
expect(taxLines?.length).toBe(0)
})
it("should remove line item tax lines succesfully with selector", async () => {
it("should delete line item tax lines succesfully with selector", async () => {
const [createdOrder] = await service.create([
{
currency_code: "eur",
},
])
const [item] = await service.addLineItems(createdOrder.id, [
const [item] = await service.createLineItems(createdOrder.id, [
{
quantity: 1,
unit_price: 100,
@@ -2428,17 +2446,20 @@ moduleIntegrationTestRunner({
},
])
const [taxLine] = await service.addLineItemTaxLines(createdOrder.id, [
{
item_id: item.id,
rate: 20,
code: "TX",
},
])
const [taxLine] = await service.createLineItemTaxLines(
createdOrder.id,
[
{
item_id: item.id,
rate: 20,
code: "TX",
},
]
)
expect(taxLine.item_id).toBe(item.id)
await service.removeLineItemTaxLines({ item_id: item.id })
await service.deleteLineItemTaxLines({ item_id: item.id })
const taxLines = await service.listLineItemTaxLines({
item_id: item.id,
+12 -3
View File
@@ -1,10 +1,12 @@
import { Modules } from "@medusajs/modules-sdk"
import { ModuleJoinerConfig } from "@medusajs/types"
import { MapToConfig } from "@medusajs/utils"
import { LineItem } from "@models"
import Order from "./models/order"
export const LinkableKeys: Record<string, string> = {
order_id: "Order",
order_item_id: "OrderLineItem",
order_id: Order.name,
order_item_id: LineItem.name,
}
const entityLinkableKeysMap: MapToConfig = {}
@@ -22,5 +24,12 @@ export const joinerConfig: ModuleJoinerConfig = {
serviceName: Modules.ORDER,
primaryKeys: ["id"],
linkableKeys: LinkableKeys,
alias: [],
alias: [
{
name: ["order", "orders"],
args: {
entity: Order.name,
},
},
],
} as ModuleJoinerConfig
@@ -33,16 +33,8 @@ export class Migration20240219102530 extends Migration {
"customer_id" TEXT NULL,
"version" INTEGER NOT NULL DEFAULT 1,
"sales_channel_id" TEXT NULL,
"status" text check (
"status" IN (
'pending',
'completed',
'draft',
'archived',
'canceled',
'requires_action'
)
) NOT NULL DEFAULT 'pending',
"status" text NOT NULL,
"is_draft_order" BOOLEAN NOT NULL DEFAULT false,
"email" text NULL,
"currency_code" text NOT NULL,
"shipping_address_id" text NULL,
@@ -59,6 +51,28 @@ export class Migration20240219102530 extends Migration {
ALTER TABLE "order"
ADD COLUMN if NOT exists "deleted_at" timestamptz NULL;
ALTER TABLE "order"
ADD COLUMN if NOT exists "is_draft_order" BOOLEAN NOT NULL DEFAULT false;
ALTER TABLE "order"
ADD COLUMN if NOT exists "version" INTEGER NOT NULL DEFAULT 1;
ALTER TABLE "order" ALTER COLUMN status TYPE text;
DROP TYPE IF EXISTS order_status_enum CASCADE;
CREATE TYPE order_status_enum AS ENUM (
'pending',
'completed',
'draft',
'archived',
'canceled',
'requires_action'
);
ALTER TABLE "order" ALTER COLUMN status DROP DEFAULT;
ALTER TABLE "order" ALTER COLUMN status TYPE order_status_enum USING (status::text::order_status_enum);
ALTER TABLE "order" ALTER COLUMN status SET DEFAULT 'pending';
ALTER TABLE "order" DROP constraint if EXISTS "FK_6ff7e874f01b478c115fdd462eb" CASCADE;
ALTER TABLE "order" DROP constraint if EXISTS "FK_19b0c6293443d1b464f604c3316" CASCADE;
@@ -129,6 +143,10 @@ export class Migration20240219102530 extends Migration {
CREATE INDEX IF NOT EXISTS "IDX_order_deleted_at" ON "order" (
deleted_at
);
CREATE INDEX IF NOT EXISTS "IDX_order_is_draft_order" ON "order" (
is_draft_order
)
WHERE deleted_at IS NOT NULL;
@@ -284,6 +302,7 @@ export class Migration20240219102530 extends Migration {
"raw_compare_at_unit_price" JSONB NULL,
"unit_price" NUMERIC NOT NULL,
"raw_unit_price" JSONB NOT NULL,
"metadata" JSONB NULL,
"created_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
"updated_at" TIMESTAMPTZ NOT NULL DEFAULT Now(),
CONSTRAINT "order_line_item_pkey" PRIMARY KEY ("id")
@@ -423,14 +442,12 @@ export class Migration20240219102530 extends Migration {
ALTER TABLE if exists "order"
ADD CONSTRAINT "order_shipping_address_id_foreign" FOREIGN KEY ("shipping_address_id") REFERENCES "order_address" ("id") ON
UPDATE CASCADE ON
DELETE
SET NULL;
DELETE CASCADE;
ALTER TABLE if exists "order"
ADD CONSTRAINT "order_billing_address_id_foreign" FOREIGN KEY ("billing_address_id") REFERENCES "order_address" ("id") ON
UPDATE CASCADE ON
DELETE
SET NULL;
DELETE CASCADE;
ALTER TABLE if exists "order_change"
ADD CONSTRAINT "order_change_order_id_foreign" FOREIGN KEY ("order_id") REFERENCES "order" ("id") ON
@@ -2,13 +2,7 @@ import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
} from "@mikro-orm/core"
import { BeforeCreate, Entity, ManyToOne, OnInit } from "@mikro-orm/core"
import AdjustmentLine from "./adjustment-line"
import LineItem from "./line-item"
@@ -28,7 +22,7 @@ export default class LineItemAdjustment extends AdjustmentLine {
entity: () => LineItem,
columnType: "text",
fieldName: "item_id",
cascade: [Cascade.REMOVE],
onDelete: "cascade",
mapToPk: true,
})
@ItemIdIndex.MikroORMIndex()
+5 -2
View File
@@ -122,15 +122,18 @@ export default class LineItem {
raw_unit_price: BigNumberRawValue
@OneToMany(() => LineItemTaxLine, (taxLine) => taxLine.item, {
cascade: [Cascade.PERSIST],
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
})
tax_lines = new Collection<LineItemTaxLine>(this)
@OneToMany(() => LineItemAdjustment, (adjustment) => adjustment.item, {
cascade: [Cascade.PERSIST],
cascade: [Cascade.PERSIST, "soft-remove" as Cascade],
})
adjustments = new Collection<LineItemAdjustment>(this)
@Property({ columnType: "jsonb", nullable: true })
metadata: Record<string, unknown> | null = null
@Property({
onCreate: () => new Date(),
columnType: "timestamptz",
@@ -7,7 +7,6 @@ import {
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
@@ -50,7 +49,7 @@ export default class OrderChangeAction {
entity: () => Order,
columnType: "text",
fieldName: "order_id",
cascade: [Cascade.REMOVE],
onDelete: "cascade",
mapToPk: true,
nullable: true,
})
@@ -70,7 +69,7 @@ export default class OrderChangeAction {
entity: () => OrderChange,
columnType: "text",
fieldName: "order_change_id",
cascade: [Cascade.REMOVE],
onDelete: "cascade",
mapToPk: true,
nullable: true,
})
+2 -2
View File
@@ -49,7 +49,7 @@ export default class OrderChange {
entity: () => Order,
columnType: "text",
fieldName: "order_id",
cascade: [Cascade.REMOVE],
onDelete: "cascade",
mapToPk: true,
})
@OrderIdIndex.MikroORMIndex()
@@ -65,7 +65,7 @@ export default class OrderChange {
version: number
@OneToMany(() => OrderChangeAction, (action) => action.order_change, {
cascade: [Cascade.PERSIST],
cascade: [Cascade.PERSIST, "sotf-remove" as Cascade],
})
actions = new Collection<OrderChangeAction>(this)
+2 -6
View File
@@ -5,7 +5,6 @@ import {
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
@@ -55,14 +54,11 @@ export default class OrderSummary {
columnType: "text",
fieldName: "order_id",
mapToPk: true,
cascade: [Cascade.REMOVE],
onDelete: "cascade",
})
order_id: string
@ManyToOne({
entity: () => Order,
fieldName: "order_id",
cascade: [Cascade.REMOVE],
@ManyToOne(() => Order, {
persist: false,
})
order: Order
+12
View File
@@ -70,6 +70,12 @@ const BillingAddressIdIndex = createPsqlIndexStatementHelper({
where: "deleted_at IS NOT NULL",
})
const IsDraftOrderIndex = createPsqlIndexStatementHelper({
tableName: "order",
columns: "is_draft_order",
where: "deleted_at IS NOT NULL",
})
@Entity({ tableName: "order" })
export default class Order {
[OptionalProps]?: OptionalOrderProps
@@ -107,6 +113,12 @@ export default class Order {
@Enum({ items: () => OrderStatus, default: OrderStatus.PENDING })
status: OrderStatus
@Property({
columnType: "boolean",
})
@IsDraftOrderIndex.MikroORMIndex()
is_draft_order = false
@Property({ columnType: "text", nullable: true })
email: string | null = null
@@ -2,13 +2,7 @@ import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
} from "@mikro-orm/core"
import { BeforeCreate, Entity, ManyToOne, OnInit } from "@mikro-orm/core"
import AdjustmentLine from "./adjustment-line"
import ShippingMethod from "./shipping-method"
@@ -29,7 +23,7 @@ export default class ShippingMethodAdjustment extends AdjustmentLine {
columnType: "text",
fieldName: "shipping_method_id",
mapToPk: true,
cascade: [Cascade.REMOVE],
onDelete: "cascade",
})
@ShippingMethodIdIdIndex.MikroORMIndex()
shipping_method_id: string
@@ -2,13 +2,7 @@ import {
createPsqlIndexStatementHelper,
generateEntityId,
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
} from "@mikro-orm/core"
import { BeforeCreate, Entity, ManyToOne, OnInit } from "@mikro-orm/core"
import ShippingMethod from "./shipping-method"
import TaxLine from "./tax-line"
@@ -29,7 +23,7 @@ export default class ShippingMethodTaxLine extends TaxLine {
fieldName: "shipping_method_id",
columnType: "text",
mapToPk: true,
cascade: [Cascade.REMOVE],
onDelete: "cascade",
})
@ShippingMethodIdIdIndex.MikroORMIndex()
shipping_method_id: string
+2 -5
View File
@@ -46,15 +46,12 @@ export default class ShippingMethod {
columnType: "text",
fieldName: "order_id",
mapToPk: true,
cascade: [Cascade.REMOVE],
onDelete: "cascade",
})
@OrderIdIndex.MikroORMIndex()
order_id: string
@ManyToOne({
entity: () => Order,
fieldName: "order_id",
cascade: [Cascade.REMOVE],
@ManyToOne(() => Order, {
persist: false,
})
order: Order
+1 -2
View File
@@ -7,7 +7,6 @@ import {
} from "@medusajs/utils"
import {
BeforeCreate,
Cascade,
Entity,
ManyToOne,
OnInit,
@@ -45,7 +44,7 @@ export default class Transaction {
entity: () => Order,
columnType: "text",
fieldName: "order_id",
cascade: [Cascade.REMOVE],
onDelete: "cascade",
mapToPk: true,
})
@OrderIdIndex.MikroORMIndex()
@@ -1,7 +1,6 @@
import {
Context,
DAL,
FilterableLineItemTaxLineProps,
FindConfig,
InternalModuleDeclaration,
IOrderModuleService,
@@ -299,7 +298,7 @@ export default class OrderModuleService<
}
if (lineItemsToCreate.length) {
await this.addLineItemsBulk_(lineItemsToCreate, sharedContext)
await this.createLineItemsBulk_(lineItemsToCreate, sharedContext)
}
return createdOrders
@@ -314,7 +313,7 @@ export default class OrderModuleService<
sharedContext?: Context
): Promise<OrderTypes.OrderDTO>
async update(
selector: Partial<OrderTypes.OrderDTO>,
selector: Partial<OrderTypes.FilterableOrderProps>,
data: OrderTypes.UpdateOrderDTO,
sharedContext?: Context
): Promise<OrderTypes.OrderDTO[]>
@@ -324,7 +323,7 @@ export default class OrderModuleService<
dataOrIdOrSelector:
| OrderTypes.UpdateOrderDTO[]
| string
| Partial<OrderTypes.OrderDTO>,
| Partial<OrderTypes.FilterableOrderProps>,
data?: OrderTypes.UpdateOrderDTO,
@MedusaContext() sharedContext: Context = {}
): Promise<OrderTypes.OrderDTO[] | OrderTypes.OrderDTO> {
@@ -344,7 +343,7 @@ export default class OrderModuleService<
dataOrIdOrSelector:
| OrderTypes.UpdateOrderDTO[]
| string
| Partial<OrderTypes.OrderDTO>,
| Partial<OrderTypes.FilterableOrderProps>,
data?: OrderTypes.UpdateOrderDTO,
@MedusaContext() sharedContext: Context = {}
) {
@@ -377,20 +376,20 @@ export default class OrderModuleService<
return result
}
addLineItems(
createLineItems(
data: OrderTypes.CreateOrderLineItemForOrderDTO
): Promise<OrderTypes.OrderLineItemDTO[]>
addLineItems(
createLineItems(
data: OrderTypes.CreateOrderLineItemForOrderDTO[]
): Promise<OrderTypes.OrderLineItemDTO[]>
addLineItems(
createLineItems(
orderId: string,
items: OrderTypes.CreateOrderLineItemDTO[],
sharedContext?: Context
): Promise<OrderTypes.OrderLineItemDTO[]>
@InjectManager("baseRepository_")
async addLineItems(
async createLineItems(
orderIdOrData:
| string
| OrderTypes.CreateOrderLineItemForOrderDTO[]
@@ -402,7 +401,7 @@ export default class OrderModuleService<
): Promise<OrderTypes.OrderLineItemDTO[]> {
let items: LineItem[] = []
if (isString(orderIdOrData)) {
items = await this.addLineItems_(
items = await this.createLineItems_(
orderIdOrData,
data as OrderTypes.CreateOrderLineItemDTO[],
sharedContext
@@ -411,7 +410,7 @@ export default class OrderModuleService<
const data = Array.isArray(orderIdOrData)
? orderIdOrData
: [orderIdOrData]
items = await this.addLineItemsBulk_(data, sharedContext)
items = await this.createLineItemsBulk_(data, sharedContext)
}
return await this.baseRepository_.serialize<OrderTypes.OrderLineItemDTO[]>(
@@ -423,7 +422,7 @@ export default class OrderModuleService<
}
@InjectTransactionManager("baseRepository_")
protected async addLineItems_(
protected async createLineItems_(
orderId: string,
items: OrderTypes.CreateOrderLineItemDTO[],
@MedusaContext() sharedContext: Context = {}
@@ -442,11 +441,11 @@ export default class OrderModuleService<
}
})
return await this.addLineItemsBulk_(toUpdate, sharedContext)
return await this.createLineItemsBulk_(toUpdate, sharedContext)
}
@InjectTransactionManager("baseRepository_")
protected async addLineItemsBulk_(
protected async createLineItemsBulk_(
data: CreateOrderLineItemDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<LineItem[]> {
@@ -479,7 +478,7 @@ export default class OrderModuleService<
data: OrderTypes.UpdateOrderLineItemWithSelectorDTO[]
): Promise<OrderTypes.OrderLineItemDTO[]>
updateLineItems(
selector: Partial<OrderTypes.OrderLineItemDTO>,
selector: Partial<OrderTypes.FilterableOrderLineItemProps>,
data: OrderTypes.UpdateOrderLineItemDTO,
sharedContext?: Context
): Promise<OrderTypes.OrderLineItemDTO[]>
@@ -494,7 +493,7 @@ export default class OrderModuleService<
lineItemIdOrDataOrSelector:
| string
| OrderTypes.UpdateOrderLineItemWithSelectorDTO[]
| Partial<OrderTypes.OrderLineItemDTO>,
| Partial<OrderTypes.FilterableOrderLineItemProps>,
data?:
| OrderTypes.UpdateOrderLineItemDTO
| Partial<OrderTypes.UpdateOrderLineItemDTO>,
@@ -688,40 +687,6 @@ export default class OrderModuleService<
return await this.orderItemService_.update(toUpdate, sharedContext)
}
async removeLineItems(
itemIds: string[],
sharedContext?: Context
): Promise<void>
async removeLineItems(itemIds: string, sharedContext?: Context): Promise<void>
async removeLineItems(
selector: Partial<OrderTypes.OrderLineItemDTO>,
sharedContext?: Context
): Promise<void>
@InjectTransactionManager("baseRepository_")
async removeLineItems(
itemIdsOrSelector: string | string[] | Partial<OrderTypes.OrderLineItemDTO>,
@MedusaContext() sharedContext: Context = {}
): Promise<void> {
let toDelete: string[]
if (isObject(itemIdsOrSelector)) {
const items = await this.listLineItems(
{ ...itemIdsOrSelector } as Partial<OrderTypes.OrderLineItemDTO>,
{},
sharedContext
)
toDelete = items.map((item) => item.id)
} else {
toDelete = Array.isArray(itemIdsOrSelector)
? itemIdsOrSelector
: [itemIdsOrSelector]
}
await this.lineItemService_.delete(toDelete, sharedContext)
}
async createAddresses(
data: OrderTypes.CreateOrderAddressDTO,
sharedContext?: Context
@@ -794,20 +759,20 @@ export default class OrderModuleService<
return await this.addressService_.update(data, sharedContext)
}
async addShippingMethods(
async createShippingMethods(
data: OrderTypes.CreateOrderShippingMethodDTO
): Promise<OrderTypes.OrderShippingMethodDTO>
async addShippingMethods(
async createShippingMethods(
data: OrderTypes.CreateOrderShippingMethodDTO[]
): Promise<OrderTypes.OrderShippingMethodDTO[]>
async addShippingMethods(
async createShippingMethods(
orderId: string,
methods: OrderTypes.CreateOrderShippingMethodDTO[],
sharedContext?: Context
): Promise<OrderTypes.OrderShippingMethodDTO[]>
@InjectManager("baseRepository_")
async addShippingMethods(
async createShippingMethods(
orderIdOrData:
| string
| OrderTypes.CreateOrderShippingMethodDTO[]
@@ -819,7 +784,7 @@ export default class OrderModuleService<
> {
let methods: ShippingMethod[]
if (isString(orderIdOrData)) {
methods = await this.addShippingMethods_(
methods = await this.createShippingMethods_(
orderIdOrData,
data!,
sharedContext
@@ -828,7 +793,7 @@ export default class OrderModuleService<
const data = Array.isArray(orderIdOrData)
? orderIdOrData
: [orderIdOrData]
methods = await this.addShippingMethodsBulk_(
methods = await this.createShippingMethodsBulk_(
data as OrderTypes.CreateOrderShippingMethodDTO[],
sharedContext
)
@@ -840,7 +805,7 @@ export default class OrderModuleService<
}
@InjectTransactionManager("baseRepository_")
protected async addShippingMethods_(
protected async createShippingMethods_(
orderId: string,
data: CreateOrderShippingMethodDTO[],
@MedusaContext() sharedContext: Context = {}
@@ -859,11 +824,11 @@ export default class OrderModuleService<
}
})
return await this.addShippingMethodsBulk_(methods, sharedContext)
return await this.createShippingMethodsBulk_(methods, sharedContext)
}
@InjectTransactionManager("baseRepository_")
protected async addShippingMethodsBulk_(
protected async createShippingMethodsBulk_(
data: OrderTypes.CreateOrderShippingMethodDTO[],
@MedusaContext() sharedContext: Context = {}
): Promise<ShippingMethod[]> {
@@ -873,60 +838,20 @@ export default class OrderModuleService<
)
}
async removeShippingMethods(
methodIds: string[],
sharedContext?: Context
): Promise<void>
async removeShippingMethods(
methodIds: string,
sharedContext?: Context
): Promise<void>
async removeShippingMethods(
selector: Partial<OrderTypes.OrderShippingMethodDTO>,
sharedContext?: Context
): Promise<void>
@InjectTransactionManager("baseRepository_")
async removeShippingMethods(
methodIdsOrSelector:
| string
| string[]
| Partial<OrderTypes.OrderShippingMethodDTO>,
@MedusaContext() sharedContext: Context = {}
): Promise<void> {
let toDelete: string[]
if (isObject(methodIdsOrSelector)) {
const methods = await this.listShippingMethods(
{
...(methodIdsOrSelector as Partial<OrderTypes.OrderShippingMethodDTO>),
},
{},
sharedContext
)
toDelete = methods.map((m) => m.id)
} else {
toDelete = Array.isArray(methodIdsOrSelector)
? methodIdsOrSelector
: [methodIdsOrSelector]
}
await this.shippingMethodService_.delete(toDelete, sharedContext)
}
async addLineItemAdjustments(
async createLineItemAdjustments(
adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[]
): Promise<OrderTypes.OrderLineItemAdjustmentDTO[]>
async addLineItemAdjustments(
async createLineItemAdjustments(
adjustment: OrderTypes.CreateOrderLineItemAdjustmentDTO
): Promise<OrderTypes.OrderLineItemAdjustmentDTO[]>
async addLineItemAdjustments(
async createLineItemAdjustments(
orderId: string,
adjustments: OrderTypes.CreateOrderLineItemAdjustmentDTO[],
sharedContext?: Context
): Promise<OrderTypes.OrderLineItemAdjustmentDTO[]>
@InjectTransactionManager("baseRepository_")
async addLineItemAdjustments(
async createLineItemAdjustments(
orderIdOrData:
| string
| OrderTypes.CreateOrderLineItemAdjustmentDTO[]
@@ -1026,46 +951,6 @@ export default class OrderModuleService<
})
}
async removeLineItemAdjustments(
adjustmentIds: string[],
sharedContext?: Context
): Promise<void>
async removeLineItemAdjustments(
adjustmentId: string,
sharedContext?: Context
): Promise<void>
async removeLineItemAdjustments(
selector: Partial<OrderTypes.OrderLineItemAdjustmentDTO>,
sharedContext?: Context
): Promise<void>
async removeLineItemAdjustments(
adjustmentIdsOrSelector:
| string
| string[]
| Partial<OrderTypes.OrderLineItemAdjustmentDTO>,
@MedusaContext() sharedContext: Context = {}
): Promise<void> {
let ids: string[]
if (isObject(adjustmentIdsOrSelector)) {
const adjustments = await this.listLineItemAdjustments(
{
...adjustmentIdsOrSelector,
} as Partial<OrderTypes.OrderLineItemAdjustmentDTO>,
{ select: ["id"] },
sharedContext
)
ids = adjustments.map((adj) => adj.id)
} else {
ids = Array.isArray(adjustmentIdsOrSelector)
? adjustmentIdsOrSelector
: [adjustmentIdsOrSelector]
}
await this.lineItemAdjustmentService_.delete(ids, sharedContext)
}
@InjectTransactionManager("baseRepository_")
async setShippingMethodAdjustments(
orderId: string,
@@ -1122,20 +1007,20 @@ export default class OrderModuleService<
})
}
async addShippingMethodAdjustments(
async createShippingMethodAdjustments(
adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[]
): Promise<OrderTypes.OrderShippingMethodAdjustmentDTO[]>
async addShippingMethodAdjustments(
async createShippingMethodAdjustments(
adjustment: OrderTypes.CreateOrderShippingMethodAdjustmentDTO
): Promise<OrderTypes.OrderShippingMethodAdjustmentDTO>
async addShippingMethodAdjustments(
async createShippingMethodAdjustments(
orderId: string,
adjustments: OrderTypes.CreateOrderShippingMethodAdjustmentDTO[],
sharedContext?: Context
): Promise<OrderTypes.OrderShippingMethodAdjustmentDTO[]>
@InjectTransactionManager("baseRepository_")
async addShippingMethodAdjustments(
async createShippingMethodAdjustments(
orderIdOrData:
| string
| OrderTypes.CreateOrderShippingMethodAdjustmentDTO[]
@@ -1196,53 +1081,13 @@ export default class OrderModuleService<
})
}
async removeShippingMethodAdjustments(
adjustmentIds: string[],
sharedContext?: Context
): Promise<void>
async removeShippingMethodAdjustments(
adjustmentId: string,
sharedContext?: Context
): Promise<void>
async removeShippingMethodAdjustments(
selector: Partial<OrderTypes.OrderShippingMethodAdjustmentDTO>,
sharedContext?: Context
): Promise<void>
async removeShippingMethodAdjustments(
adjustmentIdsOrSelector:
| string
| string[]
| Partial<OrderTypes.OrderShippingMethodAdjustmentDTO>,
@MedusaContext() sharedContext: Context = {}
): Promise<void> {
let ids: string[]
if (isObject(adjustmentIdsOrSelector)) {
const adjustments = await this.listShippingMethodAdjustments(
{
...adjustmentIdsOrSelector,
} as Partial<OrderTypes.OrderShippingMethodAdjustmentDTO>,
{ select: ["id"] },
sharedContext
)
ids = adjustments.map((adj) => adj.id)
} else {
ids = Array.isArray(adjustmentIdsOrSelector)
? adjustmentIdsOrSelector
: [adjustmentIdsOrSelector]
}
await this.shippingMethodAdjustmentService_.delete(ids, sharedContext)
}
addLineItemTaxLines(
createLineItemTaxLines(
taxLines: OrderTypes.CreateOrderLineItemTaxLineDTO[]
): Promise<OrderTypes.OrderLineItemTaxLineDTO[]>
addLineItemTaxLines(
createLineItemTaxLines(
taxLine: OrderTypes.CreateOrderLineItemTaxLineDTO
): Promise<OrderTypes.OrderLineItemTaxLineDTO>
addLineItemTaxLines(
createLineItemTaxLines(
orderId: string,
taxLines:
| OrderTypes.CreateOrderLineItemTaxLineDTO[]
@@ -1251,7 +1096,7 @@ export default class OrderModuleService<
): Promise<OrderTypes.OrderLineItemTaxLineDTO[]>
@InjectTransactionManager("baseRepository_")
async addLineItemTaxLines(
async createLineItemTaxLines(
orderIdOrData:
| string
| OrderTypes.CreateOrderLineItemTaxLineDTO[]
@@ -1346,53 +1191,13 @@ export default class OrderModuleService<
})
}
removeLineItemTaxLines(
taxLineIds: string[],
sharedContext?: Context
): Promise<void>
removeLineItemTaxLines(
taxLineIds: string,
sharedContext?: Context
): Promise<void>
removeLineItemTaxLines(
selector: FilterableLineItemTaxLineProps,
sharedContext?: Context
): Promise<void>
async removeLineItemTaxLines(
taxLineIdsOrSelector:
| string
| string[]
| OrderTypes.FilterableOrderShippingMethodTaxLineProps,
@MedusaContext() sharedContext: Context = {}
): Promise<void> {
let ids: string[]
if (isObject(taxLineIdsOrSelector)) {
const taxLines = await this.listLineItemTaxLines(
{
...(taxLineIdsOrSelector as OrderTypes.FilterableOrderLineItemTaxLineProps),
},
{ select: ["id"] },
sharedContext
)
ids = taxLines.map((taxLine) => taxLine.id)
} else {
ids = Array.isArray(taxLineIdsOrSelector)
? taxLineIdsOrSelector
: [taxLineIdsOrSelector]
}
await this.lineItemTaxLineService_.delete(ids, sharedContext)
}
addShippingMethodTaxLines(
createShippingMethodTaxLines(
taxLines: OrderTypes.CreateOrderShippingMethodTaxLineDTO[]
): Promise<OrderTypes.OrderShippingMethodTaxLineDTO[]>
addShippingMethodTaxLines(
createShippingMethodTaxLines(
taxLine: OrderTypes.CreateOrderShippingMethodTaxLineDTO
): Promise<OrderTypes.OrderShippingMethodTaxLineDTO>
addShippingMethodTaxLines(
createShippingMethodTaxLines(
orderId: string,
taxLines:
| OrderTypes.CreateOrderShippingMethodTaxLineDTO[]
@@ -1401,7 +1206,7 @@ export default class OrderModuleService<
): Promise<OrderTypes.OrderShippingMethodTaxLineDTO[]>
@InjectTransactionManager("baseRepository_")
async addShippingMethodTaxLines(
async createShippingMethodTaxLines(
orderIdOrData:
| string
| OrderTypes.CreateOrderShippingMethodTaxLineDTO[]
@@ -1496,46 +1301,6 @@ export default class OrderModuleService<
})
}
removeShippingMethodTaxLines(
taxLineIds: string[],
sharedContext?: Context
): Promise<void>
removeShippingMethodTaxLines(
taxLineIds: string,
sharedContext?: Context
): Promise<void>
removeShippingMethodTaxLines(
selector: Partial<OrderTypes.OrderShippingMethodTaxLineDTO>,
sharedContext?: Context
): Promise<void>
async removeShippingMethodTaxLines(
taxLineIdsOrSelector:
| string
| string[]
| OrderTypes.FilterableOrderShippingMethodTaxLineProps,
@MedusaContext() sharedContext: Context = {}
): Promise<void> {
let ids: string[]
if (isObject(taxLineIdsOrSelector)) {
const taxLines = await this.listShippingMethodTaxLines(
{
...(taxLineIdsOrSelector as OrderTypes.FilterableOrderShippingMethodTaxLineProps),
},
{ select: ["id"] },
sharedContext
)
ids = taxLines.map((taxLine) => taxLine.id)
} else {
ids = Array.isArray(taxLineIdsOrSelector)
? taxLineIdsOrSelector
: [taxLineIdsOrSelector]
}
await this.shippingMethodTaxLineService_.delete(ids, sharedContext)
}
async createOrderChange(
data: OrderTypes.CreateOrderChangeDTO,
sharedContext?: Context
@@ -1877,8 +1642,23 @@ export default class OrderModuleService<
return orderChanges
}
async addOrderAction(
data: OrderTypes.CreateOrderChangeActionDTO,
sharedContext?: Context
): Promise<OrderTypes.OrderChangeActionDTO>
async addOrderAction(
data: OrderTypes.CreateOrderChangeActionDTO[],
sharedContext?: Context
): Promise<OrderTypes.OrderChangeActionDTO[]>
@InjectTransactionManager("baseRepository_")
async addOrderAction(data: any, sharedContext?: Context): Promise<any> {
async addOrderAction(
data:
| OrderTypes.CreateOrderChangeActionDTO
| OrderTypes.CreateOrderChangeActionDTO[],
sharedContext?: Context
): Promise<
OrderTypes.OrderChangeActionDTO | OrderTypes.OrderChangeActionDTO[]
> {
let dataArr = Array.isArray(data) ? data : [data]
const orderChangeMap = {}
@@ -1908,7 +1688,11 @@ export default class OrderModuleService<
}
}
return await this.orderChangeActionService_.create(dataArr, sharedContext)
const actions = (await this.orderChangeActionService_.create(
dataArr,
sharedContext
)) as OrderTypes.OrderChangeActionDTO[]
return Array.isArray(data) ? actions : actions[0]
}
private async applyOrderChanges_(
+2 -2
View File
@@ -2,7 +2,7 @@ import { BigNumberInput } from "@medusajs/types"
export interface CreateOrderShippingMethodDTO {
name: string
shipping_method_id: string
shipping_option_id?: string
order_id: string
version?: number
amount: BigNumberInput
@@ -11,7 +11,7 @@ export interface CreateOrderShippingMethodDTO {
export interface UpdateOrderShippingMethodDTO {
id: string
shipping_method_id: string
shipping_option_id?: string
name?: string
amount?: BigNumberInput
data?: Record<string, unknown>