Chore/rm main entity concept (#7709)
**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
Stevche Radevski
Oli Juhl
parent
2895ccfba8
commit
48963f55ef
+95
-95
@@ -2,21 +2,18 @@ import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ICartModuleService } from "@medusajs/types"
|
||||
import { BigNumber } from "@medusajs/utils"
|
||||
import { CheckConstraintViolationException } from "@mikro-orm/core"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
|
||||
jest.setTimeout(50000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleIntegrationTestRunner<ICartModuleService>({
|
||||
moduleName: Modules.CART,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<ICartModuleService>) => {
|
||||
testSuite: ({ MikroOrmWrapper, service }) => {
|
||||
describe("Cart Module Service", () => {
|
||||
describe("create", () => {
|
||||
it("should throw an error when required params are not passed", async () => {
|
||||
const error = await service
|
||||
.create([
|
||||
.createCarts([
|
||||
{
|
||||
email: "test@email.com",
|
||||
} as any,
|
||||
@@ -29,13 +26,13 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should create a cart successfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
const [cart] = await service.list({ id: [createdCart.id] })
|
||||
const [cart] = await service.listCarts({ id: [createdCart.id] })
|
||||
|
||||
expect(cart).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -46,7 +43,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should create a cart with billing + shipping address successfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
billing_address: {
|
||||
@@ -60,7 +57,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const [cart] = await service.list(
|
||||
const [cart] = await service.listCarts(
|
||||
{ id: [createdCart.id] },
|
||||
{ relations: ["billing_address", "shipping_address"] }
|
||||
)
|
||||
@@ -89,7 +86,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
billing_address_id: createdAddress.id,
|
||||
@@ -116,7 +113,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should create a cart with items", async () => {
|
||||
const createdCart = await service.create({
|
||||
const createdCart = await service.createCarts({
|
||||
currency_code: "eur",
|
||||
items: [
|
||||
{
|
||||
@@ -127,7 +124,7 @@ moduleIntegrationTestRunner({
|
||||
],
|
||||
})
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
@@ -146,7 +143,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should create multiple carts with items", async () => {
|
||||
const createdCarts = await service.create([
|
||||
const createdCarts = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
items: [
|
||||
@@ -169,7 +166,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const carts = await service.list(
|
||||
const carts = await service.listCarts(
|
||||
{ id: createdCarts.map((c) => c.id) },
|
||||
{
|
||||
relations: ["items"],
|
||||
@@ -204,7 +201,7 @@ moduleIntegrationTestRunner({
|
||||
describe("update", () => {
|
||||
it("should throw an error if cart does not exist", async () => {
|
||||
const error = await service
|
||||
.update([
|
||||
.updateCarts([
|
||||
{
|
||||
id: "none-existing",
|
||||
},
|
||||
@@ -217,20 +214,20 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update a cart successfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
const [updatedCart] = await service.update([
|
||||
const [updatedCart] = await service.updateCarts([
|
||||
{
|
||||
id: createdCart.id,
|
||||
email: "test@email.com",
|
||||
},
|
||||
])
|
||||
|
||||
const [cart] = await service.list({ id: [createdCart.id] })
|
||||
const [cart] = await service.listCarts({ id: [createdCart.id] })
|
||||
|
||||
expect(cart).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -242,20 +239,20 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update a cart with selector successfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
const [updatedCart] = await service.update(
|
||||
const [updatedCart] = await service.updateCarts(
|
||||
{ id: createdCart.id },
|
||||
{
|
||||
email: "test@email.com",
|
||||
}
|
||||
)
|
||||
|
||||
const [cart] = await service.list({ id: [createdCart.id] })
|
||||
const [cart] = await service.listCarts({ id: [createdCart.id] })
|
||||
|
||||
expect(cart).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -267,17 +264,17 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update a cart with id successfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
const updatedCart = await service.update(createdCart.id, {
|
||||
const updatedCart = await service.updateCarts(createdCart.id, {
|
||||
email: "test@email.com",
|
||||
})
|
||||
|
||||
const [cart] = await service.list({ id: [createdCart.id] })
|
||||
const [cart] = await service.listCarts({ id: [createdCart.id] })
|
||||
|
||||
expect(cart).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -291,15 +288,15 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("delete", () => {
|
||||
it("should delete a cart successfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
await service.delete([createdCart.id])
|
||||
await service.deleteCarts([createdCart.id])
|
||||
|
||||
const carts = await service.list({ id: [createdCart.id] })
|
||||
const carts = await service.listCarts({ id: [createdCart.id] })
|
||||
|
||||
expect(carts.length).toEqual(0)
|
||||
})
|
||||
@@ -367,7 +364,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addLineItems", () => {
|
||||
it("should add a line item to cart succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -381,7 +378,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
@@ -396,7 +393,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple line items to cart succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -417,7 +414,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
@@ -440,13 +437,13 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple line items to multiple carts succesfully", async () => {
|
||||
let [eurCart] = await service.create([
|
||||
let [eurCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
let [usdCart] = await service.create([
|
||||
let [usdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "usd",
|
||||
},
|
||||
@@ -467,7 +464,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const carts = await service.list(
|
||||
const carts = await service.listCarts(
|
||||
{ id: [eurCart.id, usdCart.id] },
|
||||
{ relations: ["items"] }
|
||||
)
|
||||
@@ -501,7 +498,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should throw an error when required params are not passed adding to a single cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -522,7 +519,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should throw a generic error when required params are not passed using bulk add method", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -546,7 +543,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("updateLineItems", () => {
|
||||
it("should update a line item in cart succesfully with selector approach", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -574,7 +571,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update a line item in cart succesfully with id approach", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -599,7 +596,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update line items in carts succesfully with multi-selector approach", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -670,7 +667,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("removeLineItems", () => {
|
||||
it("should remove a line item succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -689,7 +686,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.softDeleteLineItems([item.id])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
@@ -697,7 +694,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should remove multiple line items succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -718,7 +715,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.softDeleteLineItems([item.id, item2.id])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items"],
|
||||
})
|
||||
|
||||
@@ -728,7 +725,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addShippingMethods", () => {
|
||||
it("should add a shipping method to cart succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -741,7 +738,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["shipping_methods"],
|
||||
})
|
||||
|
||||
@@ -749,7 +746,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should throw when amount is negative", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -768,13 +765,13 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple shipping methods to multiple carts succesfully", async () => {
|
||||
let [eurCart] = await service.create([
|
||||
let [eurCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
let [usdCart] = await service.create([
|
||||
let [usdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "usd",
|
||||
},
|
||||
@@ -793,7 +790,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const carts = await service.list(
|
||||
const carts = await service.listCarts(
|
||||
{ id: [eurCart.id, usdCart.id] },
|
||||
{ relations: ["shipping_methods"] }
|
||||
)
|
||||
@@ -814,7 +811,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("removeShippingMethods", () => {
|
||||
it("should remove a line item succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -831,7 +828,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.softDeleteShippingMethods([method.id])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["shipping_methods"],
|
||||
})
|
||||
|
||||
@@ -841,7 +838,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("setLineItemAdjustments", () => {
|
||||
it("should set line item adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -896,7 +893,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should replace line item adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -939,7 +936,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.adjustments"],
|
||||
})
|
||||
|
||||
@@ -963,7 +960,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should remove all line item adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1000,7 +997,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.setLineItemAdjustments(createdCart.id, [])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.adjustments"],
|
||||
})
|
||||
|
||||
@@ -1018,7 +1015,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update line item adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1062,7 +1059,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.adjustments"],
|
||||
})
|
||||
|
||||
@@ -1089,7 +1086,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addLineItemAdjustments", () => {
|
||||
it("should add line item adjustments for items in a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1126,7 +1123,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple line item adjustments for multiple line items", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1180,12 +1177,12 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add line item adjustments for line items on multiple carts", async () => {
|
||||
const [cartOne] = await service.create([
|
||||
const [cartOne] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
const [cartTwo] = await service.create([
|
||||
const [cartTwo] = await service.createCarts([
|
||||
{
|
||||
currency_code: "usd",
|
||||
},
|
||||
@@ -1261,7 +1258,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("removeLineItemAdjustments", () => {
|
||||
it("should remove a line item succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1279,6 +1276,7 @@ moduleIntegrationTestRunner({
|
||||
createdCart.id,
|
||||
[
|
||||
{
|
||||
code: "50",
|
||||
item_id: item.id,
|
||||
amount: 50,
|
||||
},
|
||||
@@ -1299,7 +1297,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("setShippingMethodAdjustments", () => {
|
||||
it("should set shipping method adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1358,7 +1356,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should replace shipping method adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1403,7 +1401,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["shipping_methods.adjustments"],
|
||||
})
|
||||
|
||||
@@ -1428,7 +1426,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should remove all shipping method adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1467,7 +1465,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.setShippingMethodAdjustments(createdCart.id, [])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["shipping_methods.adjustments"],
|
||||
})
|
||||
|
||||
@@ -1485,7 +1483,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update shipping method adjustments for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1530,7 +1528,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["shipping_methods.adjustments"],
|
||||
})
|
||||
|
||||
@@ -1557,7 +1555,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addShippingMethodAdjustments", () => {
|
||||
it("should add shipping method adjustments in a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1596,7 +1594,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple shipping method adjustments for multiple shipping methods", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1654,12 +1652,12 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add shipping method adjustments for shipping methods on multiple carts", async () => {
|
||||
const [cartOne] = await service.create([
|
||||
const [cartOne] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
const [cartTwo] = await service.create([
|
||||
const [cartTwo] = await service.createCarts([
|
||||
{
|
||||
currency_code: "usd",
|
||||
},
|
||||
@@ -1738,13 +1736,13 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should throw if shipping method is not associated with cart", async () => {
|
||||
const [cartOne] = await service.create([
|
||||
const [cartOne] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
|
||||
const [cartTwo] = await service.create([
|
||||
const [cartTwo] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1778,7 +1776,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("removeShippingMethodAdjustments", () => {
|
||||
it("should remove a shipping method succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1816,7 +1814,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("setLineItemTaxLines", () => {
|
||||
it("should set line item tax lines for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1868,7 +1866,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should replace line item tax lines for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1908,7 +1906,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.tax_lines"],
|
||||
})
|
||||
|
||||
@@ -1932,7 +1930,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should remove all line item tax lines for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -1966,7 +1964,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
await service.setLineItemTaxLines(createdCart.id, [])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.tax_lines"],
|
||||
})
|
||||
|
||||
@@ -1984,7 +1982,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update line item tax lines for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -2025,7 +2023,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.tax_lines"],
|
||||
})
|
||||
|
||||
@@ -2050,7 +2048,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should remove, update, and create line item tax lines for a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -2110,7 +2108,7 @@ moduleIntegrationTestRunner({
|
||||
// remove: should remove the initial tax line for itemOne
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, {
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
relations: ["items.tax_lines"],
|
||||
})
|
||||
|
||||
@@ -2142,7 +2140,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addLineItemAdjustments", () => {
|
||||
it("should add line item tax lines for items in a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -2176,7 +2174,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple line item tax lines for multiple line items", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -2227,12 +2225,12 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add line item tax lines for line items on multiple carts", async () => {
|
||||
const [cartOne] = await service.create([
|
||||
const [cartOne] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
])
|
||||
const [cartTwo] = await service.create([
|
||||
const [cartTwo] = await service.createCarts([
|
||||
{
|
||||
currency_code: "usd",
|
||||
},
|
||||
@@ -2308,7 +2306,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("removeLineItemAdjustments", () => {
|
||||
it("should remove line item tax line succesfully", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -2344,7 +2342,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should calculate totals of a cart", async () => {
|
||||
const [createdCart] = await service.create([
|
||||
const [createdCart] = await service.createCarts([
|
||||
{
|
||||
currency_code: "eur",
|
||||
},
|
||||
@@ -2386,7 +2384,9 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const cart = await service.retrieve(createdCart.id, { select: ["total"] })
|
||||
const cart = await service.retrieveCart(createdCart.id, {
|
||||
select: ["total"],
|
||||
})
|
||||
expect(cart.total).toBeInstanceOf(BigNumber)
|
||||
|
||||
const asJson = JSON.parse(JSON.stringify(cart))
|
||||
|
||||
@@ -8,10 +8,7 @@
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"bin": {
|
||||
"medusa-cart-seed": "dist/scripts/bin/run-seed.js"
|
||||
"node": ">=20"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CartModuleService } from "./services"
|
||||
|
||||
const service = CartModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
|
||||
export default moduleDefinition
|
||||
|
||||
@@ -1,98 +1,11 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
import {
|
||||
Address,
|
||||
Cart,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
LineItemTaxLine,
|
||||
ShippingMethod,
|
||||
ShippingMethodAdjustment,
|
||||
ShippingMethodTaxLine,
|
||||
} from "@models"
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export const LinkableKeys = {
|
||||
cart_id: Cart.name,
|
||||
line_item_id: LineItem.name,
|
||||
shipping_method_id: ShippingMethod.name,
|
||||
address_id: Address.name,
|
||||
line_item_adjustment_id: LineItemAdjustment.name,
|
||||
shipping_method_adjustment_id: ShippingMethodAdjustment.name,
|
||||
line_item_tax_line_id: LineItemTaxLine.name,
|
||||
shipping_method_tax_line_id: ShippingMethodTaxLine.name,
|
||||
}
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CART)
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
Object.entries(LinkableKeys).forEach(([key, value]) => {
|
||||
entityLinkableKeysMap[value] ??= []
|
||||
entityLinkableKeysMap[value].push({
|
||||
mapTo: key,
|
||||
valueFrom: key.split("_").pop()!,
|
||||
})
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.CART,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: [
|
||||
{
|
||||
name: ["cart", "carts"],
|
||||
args: {
|
||||
entity: Cart.name,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["line_item", "line_items"],
|
||||
args: {
|
||||
entity: LineItem.name,
|
||||
methodSuffix: "LineItems",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_method", "shipping_methods"],
|
||||
args: {
|
||||
entity: ShippingMethod.name,
|
||||
methodSuffix: "ShippingMethods",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["address", "addresses"],
|
||||
args: {
|
||||
entity: Address.name,
|
||||
methodSuffix: "Addresses",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["line_item_adjustment", "line_item_adjustments"],
|
||||
args: {
|
||||
entity: LineItemAdjustment.name,
|
||||
methodSuffix: "LineItemAdjustments",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_method_adjustment", "shipping_method_adjustments"],
|
||||
args: {
|
||||
entity: ShippingMethodAdjustment.name,
|
||||
methodSuffix: "ShippingMethodAdjustments",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["line_item_tax_line", "line_item_tax_lines"],
|
||||
args: {
|
||||
entity: LineItemTaxLine.name,
|
||||
methodSuffix: "LineItemTaxLines",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["shipping_method_tax_line", "shipping_method_tax_lines"],
|
||||
args: {
|
||||
entity: ShippingMethodTaxLine.name,
|
||||
methodSuffix: "ShippingMethodTaxLines",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CartModuleService } from "./services"
|
||||
|
||||
const service = CartModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
@@ -1,2 +0,0 @@
|
||||
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils";
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { EOL } from "os"
|
||||
import { run } from "../seed"
|
||||
|
||||
const args = process.argv
|
||||
const path = args.pop() as string
|
||||
|
||||
export default (async () => {
|
||||
const { config } = await import("dotenv")
|
||||
config()
|
||||
if (!path) {
|
||||
throw new Error(
|
||||
`filePath is required.${EOL}Example: medusa-cart-seed <filePath>`
|
||||
)
|
||||
}
|
||||
|
||||
await run({ path })
|
||||
})()
|
||||
@@ -1,63 +0,0 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { LoaderOptions, Logger, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { DALUtils, ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
import * as CartModels from "@models"
|
||||
import { EOL } from "os"
|
||||
import { resolve } from "path"
|
||||
|
||||
export async function run({
|
||||
options,
|
||||
logger,
|
||||
path,
|
||||
}: Partial<
|
||||
Pick<
|
||||
LoaderOptions<ModulesSdkTypes.ModuleServiceInitializeOptions>,
|
||||
"options" | "logger"
|
||||
>
|
||||
> & {
|
||||
path: string
|
||||
}) {
|
||||
logger ??= console as unknown as Logger
|
||||
|
||||
logger.info(`Loading seed data from ${path}...`)
|
||||
|
||||
const { cartData } = await import(
|
||||
resolve(process.cwd(), path)
|
||||
).catch((e) => {
|
||||
logger?.error(
|
||||
`Failed to load seed data from ${path}. Please, provide a relative path and check that you export the following: cartData.${EOL}${e}`
|
||||
)
|
||||
throw e
|
||||
})
|
||||
|
||||
const dbData = ModulesSdkUtils.loadDatabaseConfig(
|
||||
Modules.CART,
|
||||
options
|
||||
)!
|
||||
const entities = Object.values(
|
||||
CartModels
|
||||
) as unknown as EntitySchema[]
|
||||
const pathToMigrations = __dirname + "/../migrations"
|
||||
|
||||
const orm = await DALUtils.mikroOrmCreateConnection(
|
||||
dbData,
|
||||
entities,
|
||||
pathToMigrations
|
||||
)
|
||||
|
||||
const manager = orm.em.fork()
|
||||
|
||||
try {
|
||||
logger.info("Seeding cart data..")
|
||||
|
||||
// TODO: implement cart seed data
|
||||
// await createCarts(manager, cartsData)
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${EOL}${e}`
|
||||
)
|
||||
}
|
||||
|
||||
await orm.close(true)
|
||||
}
|
||||
@@ -54,6 +54,7 @@ type InjectedDependencies = {
|
||||
}
|
||||
|
||||
const generateMethodForModels = {
|
||||
Cart,
|
||||
Address,
|
||||
LineItem,
|
||||
LineItemAdjustment,
|
||||
@@ -63,39 +64,28 @@ const generateMethodForModels = {
|
||||
ShippingMethodTaxLine,
|
||||
}
|
||||
|
||||
export default class CartModuleService<
|
||||
TCart extends Cart = Cart,
|
||||
TAddress extends Address = Address,
|
||||
TLineItem extends LineItem = LineItem,
|
||||
TLineItemAdjustment extends LineItemAdjustment = LineItemAdjustment,
|
||||
TLineItemTaxLine extends LineItemTaxLine = LineItemTaxLine,
|
||||
TShippingMethodAdjustment extends ShippingMethodAdjustment = ShippingMethodAdjustment,
|
||||
TShippingMethodTaxLine extends ShippingMethodTaxLine = ShippingMethodTaxLine,
|
||||
TShippingMethod extends ShippingMethod = ShippingMethod
|
||||
>
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
CartTypes.CartDTO,
|
||||
{
|
||||
Address: { dto: CartTypes.CartAddressDTO }
|
||||
LineItem: { dto: CartTypes.CartLineItemDTO }
|
||||
LineItemAdjustment: { dto: CartTypes.LineItemAdjustmentDTO }
|
||||
LineItemTaxLine: { dto: CartTypes.LineItemTaxLineDTO }
|
||||
ShippingMethod: { dto: CartTypes.CartShippingMethodDTO }
|
||||
ShippingMethodAdjustment: { dto: CartTypes.ShippingMethodAdjustmentDTO }
|
||||
ShippingMethodTaxLine: { dto: CartTypes.ShippingMethodTaxLineDTO }
|
||||
}
|
||||
>(Cart, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
export default class CartModuleService
|
||||
extends ModulesSdkUtils.MedusaService<{
|
||||
Cart: { dto: CartTypes.CartDTO }
|
||||
Address: { dto: CartTypes.CartAddressDTO }
|
||||
LineItem: { dto: CartTypes.CartLineItemDTO }
|
||||
LineItemAdjustment: { dto: CartTypes.LineItemAdjustmentDTO }
|
||||
LineItemTaxLine: { dto: CartTypes.LineItemTaxLineDTO }
|
||||
ShippingMethod: { dto: CartTypes.CartShippingMethodDTO }
|
||||
ShippingMethodAdjustment: { dto: CartTypes.ShippingMethodAdjustmentDTO }
|
||||
ShippingMethodTaxLine: { dto: CartTypes.ShippingMethodTaxLineDTO }
|
||||
}>(generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
implements ICartModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected cartService_: ModulesSdkTypes.IMedusaInternalService<TCart>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
||||
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<TLineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<TLineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TLineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<TShippingMethodTaxLine>
|
||||
protected cartService_: ModulesSdkTypes.IMedusaInternalService<Cart>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<Address>
|
||||
protected lineItemService_: ModulesSdkTypes.IMedusaInternalService<LineItem>
|
||||
protected shippingMethodAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethodAdjustment>
|
||||
protected shippingMethodService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethod>
|
||||
protected lineItemAdjustmentService_: ModulesSdkTypes.IMedusaInternalService<LineItemAdjustment>
|
||||
protected lineItemTaxLineService_: ModulesSdkTypes.IMedusaInternalService<LineItemTaxLine>
|
||||
protected shippingMethodTaxLineService_: ModulesSdkTypes.IMedusaInternalService<ShippingMethodTaxLine>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -189,7 +179,8 @@ export default class CartModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
async retrieve(
|
||||
// @ts-expect-error
|
||||
async retrieveCart(
|
||||
id: string,
|
||||
config?: FindConfig<any> | undefined,
|
||||
sharedContext?: Context | undefined
|
||||
@@ -197,7 +188,7 @@ export default class CartModuleService<
|
||||
config ??= {}
|
||||
const includeTotals = this.shouldIncludeTotals(config)
|
||||
|
||||
const cart = await super.retrieve(id, config, sharedContext)
|
||||
const cart = await super.retrieveCart(id, config, sharedContext)
|
||||
|
||||
if (includeTotals) {
|
||||
createRawPropertiesFromBigNumber(decorateCartTotals(cart))
|
||||
@@ -206,7 +197,8 @@ export default class CartModuleService<
|
||||
return cart
|
||||
}
|
||||
|
||||
async list(
|
||||
// @ts-expect-error
|
||||
async listCarts(
|
||||
filters?: any,
|
||||
config?: FindConfig<any> | undefined,
|
||||
sharedContext?: Context | undefined
|
||||
@@ -214,7 +206,7 @@ export default class CartModuleService<
|
||||
config ??= {}
|
||||
const includeTotals = this.shouldIncludeTotals(config)
|
||||
|
||||
const carts = await super.list(filters, config, sharedContext)
|
||||
const carts = await super.listCarts(filters, config, sharedContext)
|
||||
|
||||
if (includeTotals) {
|
||||
carts.forEach((cart) => {
|
||||
@@ -225,7 +217,8 @@ export default class CartModuleService<
|
||||
return carts
|
||||
}
|
||||
|
||||
async listAndCount(
|
||||
// @ts-expect-error
|
||||
async listAndCountCarts(
|
||||
filters?: any,
|
||||
config?: FindConfig<any> | undefined,
|
||||
sharedContext?: Context | undefined
|
||||
@@ -233,7 +226,7 @@ export default class CartModuleService<
|
||||
config ??= {}
|
||||
const includeTotals = this.shouldIncludeTotals(config)
|
||||
|
||||
const [carts, count] = await super.listAndCount(
|
||||
const [carts, count] = await super.listAndCountCarts(
|
||||
filters,
|
||||
config,
|
||||
sharedContext
|
||||
@@ -248,26 +241,27 @@ export default class CartModuleService<
|
||||
return [carts, count]
|
||||
}
|
||||
|
||||
async create(
|
||||
// @ts-expect-error
|
||||
async createCarts(
|
||||
data: CartTypes.CreateCartDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<CartTypes.CartDTO[]>
|
||||
|
||||
async create(
|
||||
async createCarts(
|
||||
data: CartTypes.CreateCartDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<CartTypes.CartDTO>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async create(
|
||||
async createCarts(
|
||||
data: CartTypes.CreateCartDTO[] | CartTypes.CreateCartDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.CartDTO[] | CartTypes.CartDTO> {
|
||||
const input = Array.isArray(data) ? data : [data]
|
||||
|
||||
const carts = await this.create_(input, sharedContext)
|
||||
const carts = await this.createCarts_(input, sharedContext)
|
||||
|
||||
const result = await this.list(
|
||||
const result = await this.listCarts(
|
||||
{ id: carts.map((p) => p!.id) },
|
||||
{
|
||||
relations: ["shipping_address", "billing_address"],
|
||||
@@ -281,7 +275,7 @@ export default class CartModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async create_(
|
||||
protected async createCarts_(
|
||||
data: CartTypes.CreateCartDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
) {
|
||||
@@ -311,20 +305,23 @@ export default class CartModuleService<
|
||||
return createdCarts
|
||||
}
|
||||
|
||||
async update(data: CartTypes.UpdateCartDTO[]): Promise<CartTypes.CartDTO[]>
|
||||
async update(
|
||||
// @ts-expect-error
|
||||
async updateCarts(
|
||||
data: CartTypes.UpdateCartDTO[]
|
||||
): Promise<CartTypes.CartDTO[]>
|
||||
async updateCarts(
|
||||
cartId: string,
|
||||
data: CartTypes.UpdateCartDataDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<CartTypes.CartDTO>
|
||||
async update(
|
||||
async updateCarts(
|
||||
selector: Partial<CartTypes.CartDTO>,
|
||||
data: CartTypes.UpdateCartDataDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<CartTypes.CartDTO[]>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async update(
|
||||
async updateCarts(
|
||||
dataOrIdOrSelector:
|
||||
| CartTypes.UpdateCartDTO[]
|
||||
| string
|
||||
@@ -332,7 +329,11 @@ export default class CartModuleService<
|
||||
data?: CartTypes.UpdateCartDataDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.CartDTO[] | CartTypes.CartDTO> {
|
||||
const result = await this.update_(dataOrIdOrSelector, data, sharedContext)
|
||||
const result = await this.updateCarts_(
|
||||
dataOrIdOrSelector,
|
||||
data,
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const serializedResult = await this.baseRepository_.serialize<
|
||||
CartTypes.CartDTO[]
|
||||
@@ -344,7 +345,7 @@ export default class CartModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
protected async update_(
|
||||
protected async updateCarts_(
|
||||
dataOrIdOrSelector:
|
||||
| CartTypes.UpdateCartDTO[]
|
||||
| string
|
||||
@@ -428,7 +429,11 @@ export default class CartModuleService<
|
||||
items: CartTypes.CreateLineItemDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<LineItem[]> {
|
||||
const cart = await this.retrieve(cartId, { select: ["id"] }, sharedContext)
|
||||
const cart = await this.retrieveCart(
|
||||
cartId,
|
||||
{ select: ["id"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const toUpdate: CreateLineItemDTO[] = items.map((item) => {
|
||||
return {
|
||||
@@ -666,7 +671,11 @@ export default class CartModuleService<
|
||||
data: CartTypes.CreateShippingMethodForSingleCartDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<ShippingMethod[]> {
|
||||
const cart = await this.retrieve(cartId, { select: ["id"] }, sharedContext)
|
||||
const cart = await this.retrieveCart(
|
||||
cartId,
|
||||
{ select: ["id"] },
|
||||
sharedContext
|
||||
)
|
||||
|
||||
const methods = data.map((method) => {
|
||||
return {
|
||||
@@ -712,7 +721,7 @@ export default class CartModuleService<
|
||||
): Promise<CartTypes.LineItemAdjustmentDTO[]> {
|
||||
let addedAdjustments: LineItemAdjustment[] = []
|
||||
if (isString(cartIdOrData)) {
|
||||
const cart = await this.retrieve(
|
||||
const cart = await this.retrieveCart(
|
||||
cartIdOrData,
|
||||
{ select: ["id"], relations: ["items"] },
|
||||
sharedContext
|
||||
@@ -758,7 +767,7 @@ export default class CartModuleService<
|
||||
)[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.LineItemAdjustmentDTO[]> {
|
||||
const cart = await this.retrieve(
|
||||
const cart = await this.retrieveCart(
|
||||
cartId,
|
||||
{ select: ["id"], relations: ["items.adjustments"] },
|
||||
sharedContext
|
||||
@@ -813,7 +822,7 @@ export default class CartModuleService<
|
||||
)[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.ShippingMethodAdjustmentDTO[]> {
|
||||
const cart = await this.retrieve(
|
||||
const cart = await this.retrieveCart(
|
||||
cartId,
|
||||
{ select: ["id"], relations: ["shipping_methods.adjustments"] },
|
||||
sharedContext
|
||||
@@ -887,7 +896,7 @@ export default class CartModuleService<
|
||||
> {
|
||||
let addedAdjustments: ShippingMethodAdjustment[] = []
|
||||
if (isString(cartIdOrData)) {
|
||||
const cart = await this.retrieve(
|
||||
const cart = await this.retrieveCart(
|
||||
cartIdOrData,
|
||||
{ select: ["id"], relations: ["shipping_methods"] },
|
||||
sharedContext
|
||||
@@ -961,7 +970,7 @@ export default class CartModuleService<
|
||||
let addedTaxLines: LineItemTaxLine[]
|
||||
if (isString(cartIdOrData)) {
|
||||
// existence check
|
||||
await this.retrieve(cartIdOrData, { select: ["id"] }, sharedContext)
|
||||
await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext)
|
||||
|
||||
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
||||
|
||||
@@ -1000,7 +1009,7 @@ export default class CartModuleService<
|
||||
)[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.LineItemTaxLineDTO[]> {
|
||||
const cart = await this.retrieve(
|
||||
const cart = await this.retrieveCart(
|
||||
cartId,
|
||||
{ select: ["id"], relations: ["items.tax_lines"] },
|
||||
sharedContext
|
||||
@@ -1077,7 +1086,7 @@ export default class CartModuleService<
|
||||
let addedTaxLines: ShippingMethodTaxLine[]
|
||||
if (isString(cartIdOrData)) {
|
||||
// existence check
|
||||
await this.retrieve(cartIdOrData, { select: ["id"] }, sharedContext)
|
||||
await this.retrieveCart(cartIdOrData, { select: ["id"] }, sharedContext)
|
||||
|
||||
const lines = Array.isArray(taxLines) ? taxLines : [taxLines]
|
||||
|
||||
@@ -1116,7 +1125,7 @@ export default class CartModuleService<
|
||||
)[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CartTypes.ShippingMethodTaxLineDTO[]> {
|
||||
const cart = await this.retrieve(
|
||||
const cart = await this.retrieveCart(
|
||||
cartId,
|
||||
{ select: ["id"], relations: ["shipping_methods.tax_lines"] },
|
||||
sharedContext
|
||||
|
||||
Reference in New Issue
Block a user