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:
533 files changed
+6469
-9769
No files matched your search
+133
-119
@@ -1,15 +1,12 @@
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import { moduleIntegrationTestRunner, SuiteOptions } from "medusa-test-utils"
|
||||
import { moduleIntegrationTestRunner } from "medusa-test-utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
moduleIntegrationTestRunner({
|
||||
moduleIntegrationTestRunner<ICustomerModuleService>({
|
||||
moduleName: Modules.CUSTOMER,
|
||||
testSuite: ({
|
||||
MikroOrmWrapper,
|
||||
service,
|
||||
}: SuiteOptions<ICustomerModuleService>) => {
|
||||
testSuite: ({ service }) => {
|
||||
describe("Customer Module Service", () => {
|
||||
describe("create", () => {
|
||||
it("should create a single customer", async () => {
|
||||
@@ -22,7 +19,7 @@ moduleIntegrationTestRunner({
|
||||
created_by: "admin",
|
||||
metadata: { membership: "gold" },
|
||||
}
|
||||
const customer = await service.create(customerData)
|
||||
const customer = await service.createCustomers(customerData)
|
||||
|
||||
expect(customer).toEqual(
|
||||
expect.objectContaining({
|
||||
@@ -52,7 +49,7 @@ moduleIntegrationTestRunner({
|
||||
...customerData,
|
||||
has_account: true,
|
||||
}
|
||||
const [customer, customer2] = await service.create([
|
||||
const [customer, customer2] = await service.createCustomers([
|
||||
customerData,
|
||||
customerData2,
|
||||
])
|
||||
@@ -96,7 +93,7 @@ moduleIntegrationTestRunner({
|
||||
}
|
||||
|
||||
const err = await service
|
||||
.create([customerData, customerData])
|
||||
.createCustomers([customerData, customerData])
|
||||
.catch((err) => err)
|
||||
|
||||
expect(err.message).toBe(
|
||||
@@ -117,7 +114,7 @@ moduleIntegrationTestRunner({
|
||||
}
|
||||
|
||||
const err = await service
|
||||
.create([customerData, customerData])
|
||||
.createCustomers([customerData, customerData])
|
||||
.catch((err) => err)
|
||||
|
||||
expect(err.message).toBe(
|
||||
@@ -144,7 +141,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
],
|
||||
}
|
||||
const customer = await service.create(customerData)
|
||||
const customer = await service.createCustomers(customerData)
|
||||
|
||||
const [address] = await service.listAddresses({
|
||||
customer_id: customer.id,
|
||||
@@ -192,7 +189,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
],
|
||||
}
|
||||
await expect(service.create(customerData)).rejects.toThrow(
|
||||
await expect(service.createCustomers(customerData)).rejects.toThrow(
|
||||
/Customer address with customer_id: .*? already exists./
|
||||
)
|
||||
})
|
||||
@@ -216,7 +213,7 @@ moduleIntegrationTestRunner({
|
||||
metadata: { membership: "silver" },
|
||||
},
|
||||
]
|
||||
const customer = await service.create(customersData)
|
||||
const customer = await service.createCustomers(customersData)
|
||||
|
||||
expect(customer).toEqual(
|
||||
expect.arrayContaining([
|
||||
@@ -245,7 +242,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("createCustomerGroup", () => {
|
||||
it("should create a single customer group", async () => {
|
||||
const group = await service.createCustomerGroup({
|
||||
const group = await service.createCustomerGroups({
|
||||
name: "VIP Customers",
|
||||
metadata: { priority: "high" },
|
||||
created_by: "admin",
|
||||
@@ -262,7 +259,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should create multiple customer groups", async () => {
|
||||
const groups = await service.createCustomerGroup([
|
||||
const groups = await service.createCustomerGroups([
|
||||
{
|
||||
name: "VIP Customers",
|
||||
metadata: { priority: "high" },
|
||||
@@ -296,7 +293,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("list", () => {
|
||||
it("should list all customers when no filters are applied", async () => {
|
||||
await service.create([
|
||||
await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -309,7 +306,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
const customers = await service.list()
|
||||
const customers = await service.listCustomers()
|
||||
|
||||
expect(customers.length).toBeGreaterThanOrEqual(2)
|
||||
expect(customers).toEqual(
|
||||
@@ -329,7 +326,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should list customers filtered by a specific email", async () => {
|
||||
await service.create([
|
||||
await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -343,7 +340,7 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
const filter = { email: "unique.email@example.com" }
|
||||
const customers = await service.list(filter)
|
||||
const customers = await service.listCustomers(filter)
|
||||
|
||||
expect(customers.length).toBe(1)
|
||||
expect(customers[0]).toEqual(
|
||||
@@ -356,9 +353,9 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should list customers by a specific customer group", async () => {
|
||||
const vipGroup = await service.createCustomerGroup({ name: "VIP" })
|
||||
const vipGroup = await service.createCustomerGroups({ name: "VIP" })
|
||||
|
||||
const [john] = await service.create([
|
||||
const [john] = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -377,7 +374,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
const filter = { groups: vipGroup.id }
|
||||
const customers = await service.list(filter)
|
||||
const customers = await service.listCustomers(filter)
|
||||
|
||||
expect(customers).toEqual(
|
||||
expect.arrayContaining([
|
||||
@@ -402,14 +399,14 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addCustomerToGroup", () => {
|
||||
it("should add a single customer to a customer group", async () => {
|
||||
const [customer] = await service.create([
|
||||
const [customer] = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
email: "john.doe@example.com",
|
||||
},
|
||||
])
|
||||
const [group] = await service.createCustomerGroup([{ name: "VIP" }])
|
||||
const [group] = await service.createCustomerGroups([{ name: "VIP" }])
|
||||
|
||||
const result = await service.addCustomerToGroup({
|
||||
customer_id: customer.id,
|
||||
@@ -421,7 +418,7 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
|
||||
// Additional validation (optional): retrieve the customer and check if the group is assigned
|
||||
const updatedCustomer = await service.retrieve(customer.id, {
|
||||
const updatedCustomer = await service.retrieveCustomer(customer.id, {
|
||||
relations: ["groups"],
|
||||
})
|
||||
expect(updatedCustomer.groups).toContainEqual(
|
||||
@@ -430,7 +427,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple customers to customer groups", async () => {
|
||||
const customers = await service.create([
|
||||
const customers = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -442,7 +439,7 @@ moduleIntegrationTestRunner({
|
||||
email: "jane.smith@example.com",
|
||||
},
|
||||
])
|
||||
const groups = await service.createCustomerGroup([
|
||||
const groups = await service.createCustomerGroups([
|
||||
{ name: "VIP" },
|
||||
{ name: "Regular" },
|
||||
])
|
||||
@@ -462,9 +459,12 @@ moduleIntegrationTestRunner({
|
||||
)
|
||||
|
||||
for (const customer of customers) {
|
||||
const updatedCustomer = await service.retrieve(customer.id, {
|
||||
relations: ["groups"],
|
||||
})
|
||||
const updatedCustomer = await service.retrieveCustomer(
|
||||
customer.id,
|
||||
{
|
||||
relations: ["groups"],
|
||||
}
|
||||
)
|
||||
expect(updatedCustomer.groups).toContainEqual(
|
||||
expect.objectContaining({
|
||||
id: groups[customers.indexOf(customer) % groups.length].id,
|
||||
@@ -476,7 +476,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("update", () => {
|
||||
it("should update a single customer", async () => {
|
||||
const [customer] = await service.create([
|
||||
const [customer] = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -485,7 +485,10 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
const updateData = { first_name: "Jonathan" }
|
||||
const updatedCustomer = await service.update(customer.id, updateData)
|
||||
const updatedCustomer = await service.updateCustomers(
|
||||
customer.id,
|
||||
updateData
|
||||
)
|
||||
|
||||
expect(updatedCustomer).toEqual(
|
||||
expect.objectContaining({ id: customer.id, first_name: "Jonathan" })
|
||||
@@ -493,7 +496,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update multiple customers by IDs", async () => {
|
||||
const customers = await service.create([
|
||||
const customers = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -508,7 +511,10 @@ moduleIntegrationTestRunner({
|
||||
|
||||
const updateData = { last_name: "Updated" }
|
||||
const customerIds = customers.map((customer) => customer.id)
|
||||
const updatedCustomers = await service.update(customerIds, updateData)
|
||||
const updatedCustomers = await service.updateCustomers(
|
||||
customerIds,
|
||||
updateData
|
||||
)
|
||||
|
||||
updatedCustomers.forEach((updatedCustomer) => {
|
||||
expect(updatedCustomer).toEqual(
|
||||
@@ -518,7 +524,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update customers using a selector", async () => {
|
||||
await service.create([
|
||||
await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -533,7 +539,10 @@ moduleIntegrationTestRunner({
|
||||
|
||||
const selector = { last_name: "Doe" }
|
||||
const updateData = { last_name: "Updated" }
|
||||
const updatedCustomers = await service.update(selector, updateData)
|
||||
const updatedCustomers = await service.updateCustomers(
|
||||
selector,
|
||||
updateData
|
||||
)
|
||||
|
||||
updatedCustomers.forEach((updatedCustomer) => {
|
||||
expect(updatedCustomer).toEqual(
|
||||
@@ -545,7 +554,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("delete", () => {
|
||||
it("should delete a single customer", async () => {
|
||||
const [customer] = await service.create([
|
||||
const [customer] = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -553,15 +562,15 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
])
|
||||
|
||||
await service.delete(customer.id)
|
||||
await service.deleteCustomers(customer.id)
|
||||
|
||||
await expect(service.retrieve(customer.id)).rejects.toThrow(
|
||||
await expect(service.retrieveCustomer(customer.id)).rejects.toThrow(
|
||||
`Customer with id: ${customer.id} was not found`
|
||||
)
|
||||
})
|
||||
|
||||
it("should delete multiple customers by IDs", async () => {
|
||||
const customers = await service.create([
|
||||
const customers = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -575,17 +584,17 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
const customerIds = customers.map((customer) => customer.id)
|
||||
await service.delete(customerIds)
|
||||
await service.deleteCustomers(customerIds)
|
||||
|
||||
for (const customer of customers) {
|
||||
await expect(service.retrieve(customer.id)).rejects.toThrow(
|
||||
await expect(service.retrieveCustomer(customer.id)).rejects.toThrow(
|
||||
`Customer with id: ${customer.id} was not found`
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
it("should delete customers using a selector", async () => {
|
||||
await service.create([
|
||||
await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -599,19 +608,21 @@ moduleIntegrationTestRunner({
|
||||
])
|
||||
|
||||
const selector = { last_name: "Doe" }
|
||||
await service.delete(selector)
|
||||
await service.deleteCustomers(selector)
|
||||
|
||||
const remainingCustomers = await service.list({ last_name: "Doe" })
|
||||
const remainingCustomers = await service.listCustomers({
|
||||
last_name: "Doe",
|
||||
})
|
||||
expect(remainingCustomers.length).toBe(0)
|
||||
})
|
||||
|
||||
it("should cascade address relationship when deleting customer", async () => {
|
||||
// Creating a customer and an address
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
await service.addAddresses({
|
||||
await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -620,12 +631,15 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
// verify that the address was added
|
||||
const customerWithAddress = await service.retrieve(customer.id, {
|
||||
relations: ["addresses"],
|
||||
})
|
||||
const customerWithAddress = await service.retrieveCustomer(
|
||||
customer.id,
|
||||
{
|
||||
relations: ["addresses"],
|
||||
}
|
||||
)
|
||||
expect(customerWithAddress.addresses?.length).toBe(1)
|
||||
|
||||
await service.delete(customer.id)
|
||||
await service.deleteCustomers(customer.id)
|
||||
|
||||
const res = await service.listAddresses({
|
||||
customer_id: customer.id,
|
||||
@@ -635,11 +649,11 @@ moduleIntegrationTestRunner({
|
||||
|
||||
it("should cascade relationship when deleting customer", async () => {
|
||||
// Creating a customer and a group
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const group = await service.createCustomerGroup({ name: "VIP" })
|
||||
const group = await service.createCustomerGroups({ name: "VIP" })
|
||||
|
||||
// Adding the customer to the groups
|
||||
await service.addCustomerToGroup({
|
||||
@@ -647,7 +661,7 @@ moduleIntegrationTestRunner({
|
||||
customer_group_id: group.id,
|
||||
})
|
||||
|
||||
await service.delete(customer.id)
|
||||
await service.deleteCustomers(customer.id)
|
||||
|
||||
const res = await service.listCustomerGroupCustomers({
|
||||
customer_id: customer.id,
|
||||
@@ -659,7 +673,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("deleteCustomerGroup", () => {
|
||||
it("should delete a single customer group", async () => {
|
||||
const [group] = await service.createCustomerGroup([{ name: "VIP" }])
|
||||
const [group] = await service.createCustomerGroups([{ name: "VIP" }])
|
||||
await service.deleteCustomerGroups(group.id)
|
||||
|
||||
await expect(
|
||||
@@ -670,7 +684,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should delete multiple customer groups by IDs", async () => {
|
||||
const groups = await service.createCustomerGroup([
|
||||
const groups = await service.createCustomerGroups([
|
||||
{ name: "VIP" },
|
||||
{ name: "Regular" },
|
||||
])
|
||||
@@ -688,7 +702,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should delete customer groups using a selector", async () => {
|
||||
await service.createCustomerGroup([
|
||||
await service.createCustomerGroups([
|
||||
{ name: "VIP" },
|
||||
{ name: "Regular" },
|
||||
])
|
||||
@@ -704,11 +718,11 @@ moduleIntegrationTestRunner({
|
||||
|
||||
it("should cascade relationship when deleting customer group", async () => {
|
||||
// Creating a customer and a group
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const group = await service.createCustomerGroup({ name: "VIP" })
|
||||
const group = await service.createCustomerGroups({ name: "VIP" })
|
||||
|
||||
// Adding the customer to the groups
|
||||
await service.addCustomerToGroup({
|
||||
@@ -728,18 +742,18 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("addAddresses", () => {
|
||||
it("should add a single address to a customer", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const address = await service.addAddresses({
|
||||
const address = await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
postal_code: "10001",
|
||||
country_code: "US",
|
||||
})
|
||||
const [customerWithAddress] = await service.list(
|
||||
const [customerWithAddress] = await service.listCustomers(
|
||||
{ id: customer.id },
|
||||
{ relations: ["addresses"] }
|
||||
)
|
||||
@@ -750,11 +764,11 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should add multiple addresses to a customer", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const addresses = await service.addAddresses([
|
||||
const addresses = await service.createAddresses([
|
||||
{
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
@@ -770,7 +784,7 @@ moduleIntegrationTestRunner({
|
||||
country_code: "US",
|
||||
},
|
||||
])
|
||||
const [customerWithAddresses] = await service.list(
|
||||
const [customerWithAddresses] = await service.listCustomers(
|
||||
{ id: customer.id },
|
||||
{ relations: ["addresses"] }
|
||||
)
|
||||
@@ -784,11 +798,11 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should only be possible to add one default shipping address per customer", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
await service.addAddresses({
|
||||
await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -796,7 +810,7 @@ moduleIntegrationTestRunner({
|
||||
country_code: "US",
|
||||
is_default_shipping: true,
|
||||
})
|
||||
await service.addAddresses({
|
||||
await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -806,7 +820,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
await expect(
|
||||
service.addAddresses({
|
||||
service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -820,11 +834,11 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should only be possible to add one default billing address per customer", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
await service.addAddresses({
|
||||
await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -832,7 +846,7 @@ moduleIntegrationTestRunner({
|
||||
country_code: "US",
|
||||
is_default_billing: true,
|
||||
})
|
||||
await service.addAddresses({
|
||||
await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -842,7 +856,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
await expect(
|
||||
service.addAddresses({
|
||||
service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -858,11 +872,11 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("updateAddresses", () => {
|
||||
it("should update a single address", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const address = await service.addAddresses({
|
||||
const address = await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
address_name: "Home",
|
||||
address_1: "123 Main St",
|
||||
@@ -873,7 +887,7 @@ moduleIntegrationTestRunner({
|
||||
address_1: "456 Main St",
|
||||
})
|
||||
|
||||
const updatedCustomer = await service.retrieve(customer.id, {
|
||||
const updatedCustomer = await service.retrieveCustomer(customer.id, {
|
||||
select: ["id"],
|
||||
relations: ["addresses"],
|
||||
})
|
||||
@@ -888,16 +902,16 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update multiple addresses", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const address1 = await service.addAddresses({
|
||||
const address1 = await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
address_name: "Home",
|
||||
address_1: "123 Main St",
|
||||
})
|
||||
const address2 = await service.addAddresses({
|
||||
const address2 = await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
address_name: "Work",
|
||||
address_1: "456 Main St",
|
||||
@@ -910,7 +924,7 @@ moduleIntegrationTestRunner({
|
||||
}
|
||||
)
|
||||
|
||||
const updatedCustomer = await service.retrieve(customer.id, {
|
||||
const updatedCustomer = await service.retrieveCustomer(customer.id, {
|
||||
select: ["id"],
|
||||
relations: ["addresses"],
|
||||
})
|
||||
@@ -930,11 +944,11 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should update multiple addresses with ids", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const [address1, address2] = await service.addAddresses([
|
||||
const [address1, address2] = await service.createAddresses([
|
||||
{
|
||||
customer_id: customer.id,
|
||||
address_name: "Home",
|
||||
@@ -951,7 +965,7 @@ moduleIntegrationTestRunner({
|
||||
address_name: "Under Construction",
|
||||
})
|
||||
|
||||
const updatedCustomer = await service.retrieve(customer.id, {
|
||||
const updatedCustomer = await service.retrieveCustomer(customer.id, {
|
||||
select: ["id"],
|
||||
relations: ["addresses"],
|
||||
})
|
||||
@@ -971,7 +985,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should fail when updating address to a default shipping address when one already exists", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
addresses: [
|
||||
@@ -982,7 +996,7 @@ moduleIntegrationTestRunner({
|
||||
},
|
||||
],
|
||||
})
|
||||
const address = await service.addAddresses({
|
||||
const address = await service.createAddresses({
|
||||
customer_id: customer.id,
|
||||
address_name: "Work",
|
||||
address_1: "456 Main St",
|
||||
@@ -998,11 +1012,11 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("listAddresses", () => {
|
||||
it("should list all addresses for a customer", async () => {
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const [address1, address2] = await service.addAddresses([
|
||||
const [address1, address2] = await service.createAddresses([
|
||||
{
|
||||
customer_id: customer.id,
|
||||
address_name: "Home",
|
||||
@@ -1040,14 +1054,14 @@ moduleIntegrationTestRunner({
|
||||
describe("removeCustomerFromGroup", () => {
|
||||
it("should remove a single customer from a group", async () => {
|
||||
// Creating a customer and a group
|
||||
const [customer] = await service.create([
|
||||
const [customer] = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
email: "john.doe@example.com",
|
||||
},
|
||||
])
|
||||
const [group] = await service.createCustomerGroup([{ name: "VIP" }])
|
||||
const [group] = await service.createCustomerGroups([{ name: "VIP" }])
|
||||
|
||||
// Adding the customer to the group
|
||||
await service.addCustomerToGroup({
|
||||
@@ -1055,7 +1069,7 @@ moduleIntegrationTestRunner({
|
||||
customer_group_id: group.id,
|
||||
})
|
||||
|
||||
const [customerInGroup] = await service.list(
|
||||
const [customerInGroup] = await service.listCustomers(
|
||||
{ id: customer.id },
|
||||
{ relations: ["groups"] }
|
||||
)
|
||||
@@ -1069,7 +1083,7 @@ moduleIntegrationTestRunner({
|
||||
customer_group_id: group.id,
|
||||
})
|
||||
|
||||
const [updatedCustomer] = await service.list(
|
||||
const [updatedCustomer] = await service.listCustomers(
|
||||
{ id: customer.id },
|
||||
{ relations: ["groups"] }
|
||||
)
|
||||
@@ -1078,7 +1092,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
it("should remove multiple customers from groups", async () => {
|
||||
// Creating multiple customers and groups
|
||||
const customers = await service.create([
|
||||
const customers = await service.createCustomers([
|
||||
{
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
@@ -1090,7 +1104,7 @@ moduleIntegrationTestRunner({
|
||||
email: "jane.smith@example.com",
|
||||
},
|
||||
])
|
||||
const groups = await service.createCustomerGroup([
|
||||
const groups = await service.createCustomerGroups([
|
||||
{ name: "VIP" },
|
||||
{ name: "Regular" },
|
||||
])
|
||||
@@ -1111,7 +1125,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
// Verification for each customer
|
||||
for (const pair of pairsToRemove) {
|
||||
const [updatedCustomer] = await service.list(
|
||||
const [updatedCustomer] = await service.listCustomers(
|
||||
{ id: pair.customer_id },
|
||||
{ relations: ["groups"] }
|
||||
)
|
||||
@@ -1124,15 +1138,15 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("softDelete", () => {
|
||||
it("should soft delete a single customer", async () => {
|
||||
const [customer] = await service.create([
|
||||
const [customer] = await service.createCustomers([
|
||||
{ first_name: "John", last_name: "Doe" },
|
||||
])
|
||||
await service.softDelete([customer.id])
|
||||
await service.softDeleteCustomers([customer.id])
|
||||
|
||||
const res = await service.list({ id: customer.id })
|
||||
const res = await service.listCustomers({ id: customer.id })
|
||||
expect(res.length).toBe(0)
|
||||
|
||||
const deletedCustomer = await service.retrieve(customer.id, {
|
||||
const deletedCustomer = await service.retrieveCustomer(customer.id, {
|
||||
withDeleted: true,
|
||||
})
|
||||
|
||||
@@ -1140,17 +1154,17 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should soft delete multiple customers", async () => {
|
||||
const customers = await service.create([
|
||||
const customers = await service.createCustomers([
|
||||
{ first_name: "John", last_name: "Doe" },
|
||||
{ first_name: "Jane", last_name: "Smith" },
|
||||
])
|
||||
const customerIds = customers.map((customer) => customer.id)
|
||||
await service.softDelete(customerIds)
|
||||
await service.softDeleteCustomers(customerIds)
|
||||
|
||||
const res = await service.list({ id: customerIds })
|
||||
const res = await service.listCustomers({ id: customerIds })
|
||||
expect(res.length).toBe(0)
|
||||
|
||||
const deletedCustomers = await service.list(
|
||||
const deletedCustomers = await service.listCustomers(
|
||||
{ id: customerIds },
|
||||
{ withDeleted: true }
|
||||
)
|
||||
@@ -1159,11 +1173,11 @@ moduleIntegrationTestRunner({
|
||||
|
||||
it("should remove customer in group relation", async () => {
|
||||
// Creating a customer and a group
|
||||
const customer = await service.create({
|
||||
const customer = await service.createCustomers({
|
||||
first_name: "John",
|
||||
last_name: "Doe",
|
||||
})
|
||||
const group = await service.createCustomerGroup({ name: "VIP" })
|
||||
const group = await service.createCustomerGroups({ name: "VIP" })
|
||||
|
||||
// Adding the customer to the group
|
||||
await service.addCustomerToGroup({
|
||||
@@ -1171,7 +1185,7 @@ moduleIntegrationTestRunner({
|
||||
customer_group_id: group.id,
|
||||
})
|
||||
|
||||
await service.softDelete([customer.id])
|
||||
await service.softDeleteCustomers([customer.id])
|
||||
|
||||
const resGroup = await service.retrieveCustomerGroup(group.id, {
|
||||
relations: ["customers"],
|
||||
@@ -1182,36 +1196,36 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("restore", () => {
|
||||
it("should restore a single customer", async () => {
|
||||
const [customer] = await service.create([
|
||||
const [customer] = await service.createCustomers([
|
||||
{ first_name: "John", last_name: "Doe" },
|
||||
])
|
||||
await service.softDelete([customer.id])
|
||||
await service.softDeleteCustomers([customer.id])
|
||||
|
||||
const res = await service.list({ id: customer.id })
|
||||
const res = await service.listCustomers({ id: customer.id })
|
||||
expect(res.length).toBe(0)
|
||||
|
||||
await service.restore([customer.id])
|
||||
await service.restoreCustomers([customer.id])
|
||||
|
||||
const restoredCustomer = await service.retrieve(customer.id, {
|
||||
const restoredCustomer = await service.retrieveCustomer(customer.id, {
|
||||
withDeleted: true,
|
||||
})
|
||||
expect(restoredCustomer.deleted_at).toBeNull()
|
||||
})
|
||||
|
||||
it("should restore multiple customers", async () => {
|
||||
const customers = await service.create([
|
||||
const customers = await service.createCustomers([
|
||||
{ first_name: "John", last_name: "Doe" },
|
||||
{ first_name: "Jane", last_name: "Smith" },
|
||||
])
|
||||
const customerIds = customers.map((customer) => customer.id)
|
||||
await service.softDelete(customerIds)
|
||||
await service.softDeleteCustomers(customerIds)
|
||||
|
||||
const res = await service.list({ id: customerIds })
|
||||
const res = await service.listCustomers({ id: customerIds })
|
||||
expect(res.length).toBe(0)
|
||||
|
||||
await service.restore(customerIds)
|
||||
await service.restoreCustomers(customerIds)
|
||||
|
||||
const restoredCustomers = await service.list(
|
||||
const restoredCustomers = await service.listCustomers(
|
||||
{ id: customerIds },
|
||||
{ withDeleted: true }
|
||||
)
|
||||
@@ -1221,7 +1235,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("softDeleteCustomerGroup", () => {
|
||||
it("should soft delete a single customer group", async () => {
|
||||
const [group] = await service.createCustomerGroup([{ name: "VIP" }])
|
||||
const [group] = await service.createCustomerGroups([{ name: "VIP" }])
|
||||
await service.softDeleteCustomerGroups([group.id])
|
||||
|
||||
const res = await service.listCustomerGroups({ id: group.id })
|
||||
@@ -1235,7 +1249,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should soft delete multiple customer groups", async () => {
|
||||
const groups = await service.createCustomerGroup([
|
||||
const groups = await service.createCustomerGroups([
|
||||
{ name: "VIP" },
|
||||
{ name: "Regular" },
|
||||
])
|
||||
@@ -1255,7 +1269,7 @@ moduleIntegrationTestRunner({
|
||||
|
||||
describe("restoreCustomerGroup", () => {
|
||||
it("should restore a single customer group", async () => {
|
||||
const [group] = await service.createCustomerGroup([{ name: "VIP" }])
|
||||
const [group] = await service.createCustomerGroups([{ name: "VIP" }])
|
||||
await service.softDeleteCustomerGroups([group.id])
|
||||
|
||||
const res = await service.listCustomerGroups({ id: group.id })
|
||||
@@ -1270,7 +1284,7 @@ moduleIntegrationTestRunner({
|
||||
})
|
||||
|
||||
it("should restore multiple customer groups", async () => {
|
||||
const groups = await service.createCustomerGroup([
|
||||
const groups = await service.createCustomerGroups([
|
||||
{ name: "VIP" },
|
||||
{ name: "Regular" },
|
||||
])
|
||||
|
||||
@@ -8,10 +8,7 @@
|
||||
"dist"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=16"
|
||||
},
|
||||
"bin": {
|
||||
"medusa-customer-seed": "dist/scripts/bin/run-seed.js"
|
||||
"node": ">=20"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CustomerModuleService } from "@services"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
service: CustomerModuleService,
|
||||
}
|
||||
export default moduleDefinition
|
||||
@@ -1,49 +1,21 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
import { Address, Customer, CustomerGroup } from "@models"
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
export const LinkableKeys = {
|
||||
customer_id: Customer.name,
|
||||
customer_group_id: CustomerGroup.name,
|
||||
customer_address_id: Address.name,
|
||||
}
|
||||
|
||||
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.CUSTOMER,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
export const joinerConfig = defineJoinerConfig(Modules.CUSTOMER, {
|
||||
alias: [
|
||||
{
|
||||
name: ["customer", "customers"],
|
||||
args: {
|
||||
entity: Customer.name,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["customer_group", "customer_groups"],
|
||||
args: {
|
||||
entity: CustomerGroup.name,
|
||||
methodSuffix: "CustomerGroups",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["customer_address", "customer_addresses"],
|
||||
args: {
|
||||
entity: Address.name,
|
||||
entity: "Address",
|
||||
methodSuffix: "Addresses",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
@@ -2,3 +2,4 @@ export { default as Address } from "./address"
|
||||
export { default as Customer } from "./customer"
|
||||
export { default as CustomerGroup } from "./customer-group"
|
||||
export { default as CustomerGroupCustomer } from "./customer-group-customer"
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { CustomerModuleService } from "@services"
|
||||
|
||||
const service = CustomerModuleService
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
}
|
||||
@@ -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,58 +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 CustomerModels 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 { customerData } = 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: customerData.${EOL}${e}`
|
||||
)
|
||||
throw e
|
||||
}
|
||||
)
|
||||
|
||||
const dbData = ModulesSdkUtils.loadDatabaseConfig(Modules.CUSTOMER, options)!
|
||||
const entities = Object.values(CustomerModels) 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 customer data..")
|
||||
|
||||
// TODO: implement customer seed data
|
||||
// await createCustomers(manager, customersData)
|
||||
} catch (e) {
|
||||
logger.error(
|
||||
`Failed to insert the seed data in the PostgreSQL database ${dbData.clientUrl}.${EOL}${e}`
|
||||
)
|
||||
}
|
||||
|
||||
await orm.close(true)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import {
|
||||
Context,
|
||||
CustomerAddressDTO,
|
||||
CustomerDTO,
|
||||
CustomerGroupCustomerDTO,
|
||||
CustomerGroupDTO,
|
||||
CustomerTypes,
|
||||
DAL,
|
||||
ICustomerModuleService,
|
||||
@@ -14,16 +17,16 @@ import {
|
||||
InjectTransactionManager,
|
||||
isString,
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
MedusaService,
|
||||
} from "@medusajs/utils"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
import { EntityManager } from "@mikro-orm/core"
|
||||
import {
|
||||
Address,
|
||||
Customer,
|
||||
CustomerGroup,
|
||||
CustomerGroupCustomer,
|
||||
} from "@models"
|
||||
import { EntityManager } from "@mikro-orm/core"
|
||||
import { entityNameToLinkableKeysMap, joinerConfig } from "../joiner-config"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -33,33 +36,23 @@ type InjectedDependencies = {
|
||||
customerGroupCustomerService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
}
|
||||
|
||||
const generateMethodForModels = {
|
||||
Address: { singular: "Address", plural: "Addresses" },
|
||||
CustomerGroup,
|
||||
CustomerGroupCustomer,
|
||||
}
|
||||
|
||||
export default class CustomerModuleService<
|
||||
TAddress extends Address = Address,
|
||||
TCustomer extends Customer = Customer,
|
||||
TCustomerGroup extends CustomerGroup = CustomerGroup,
|
||||
TCustomerGroupCustomer extends CustomerGroupCustomer = CustomerGroupCustomer
|
||||
>
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
CustomerDTO,
|
||||
{
|
||||
Address: { dto: any }
|
||||
CustomerGroup: { dto: any }
|
||||
CustomerGroupCustomer: { dto: any }
|
||||
}
|
||||
>(Customer, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
export default class CustomerModuleService
|
||||
extends MedusaService<{
|
||||
Address: { dto: CustomerAddressDTO }
|
||||
Customer: { dto: CustomerDTO }
|
||||
CustomerGroup: { dto: CustomerGroupDTO }
|
||||
CustomerGroupCustomer: { dto: CustomerGroupCustomerDTO }
|
||||
}>(
|
||||
{ Address, Customer, CustomerGroup, CustomerGroupCustomer },
|
||||
entityNameToLinkableKeysMap
|
||||
)
|
||||
implements ICustomerModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected customerService_: ModulesSdkTypes.IMedusaInternalService<TCustomer>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<TAddress>
|
||||
protected customerGroupService_: ModulesSdkTypes.IMedusaInternalService<TCustomerGroup>
|
||||
protected customerGroupCustomerService_: ModulesSdkTypes.IMedusaInternalService<TCustomerGroupCustomer>
|
||||
protected customerService_: ModulesSdkTypes.IMedusaInternalService<Customer>
|
||||
protected addressService_: ModulesSdkTypes.IMedusaInternalService<Address>
|
||||
protected customerGroupService_: ModulesSdkTypes.IMedusaInternalService<CustomerGroup>
|
||||
protected customerGroupCustomerService_: ModulesSdkTypes.IMedusaInternalService<CustomerGroupCustomer>
|
||||
|
||||
constructor(
|
||||
{
|
||||
@@ -85,24 +78,25 @@ export default class CustomerModuleService<
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
async create(
|
||||
// @ts-expect-error
|
||||
async createCustomers(
|
||||
data: CustomerTypes.CreateCustomerDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerDTO>
|
||||
|
||||
async create(
|
||||
async createCustomers(
|
||||
data: CustomerTypes.CreateCustomerDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerDTO[]>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async create(
|
||||
async createCustomers(
|
||||
dataOrArray:
|
||||
| CustomerTypes.CreateCustomerDTO
|
||||
| CustomerTypes.CreateCustomerDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<CustomerTypes.CustomerDTO | CustomerTypes.CustomerDTO[]> {
|
||||
const customers = await this.create_(dataOrArray, sharedContext)
|
||||
const customers = await this.createCustomers_(dataOrArray, sharedContext)
|
||||
|
||||
const serialized = await this.baseRepository_.serialize<
|
||||
CustomerTypes.CustomerDTO[]
|
||||
@@ -114,7 +108,7 @@ export default class CustomerModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async create_(
|
||||
async createCustomers_(
|
||||
dataOrArray:
|
||||
| CustomerTypes.CreateCustomerDTO
|
||||
| CustomerTypes.CreateCustomerDTO[],
|
||||
@@ -137,29 +131,30 @@ export default class CustomerModuleService<
|
||||
})
|
||||
.flat()
|
||||
|
||||
await this.addAddresses(addressDataWithCustomerIds, sharedContext)
|
||||
await this.createAddresses(addressDataWithCustomerIds, sharedContext)
|
||||
|
||||
return customers as unknown as CustomerTypes.CustomerDTO[]
|
||||
}
|
||||
|
||||
update(
|
||||
// @ts-expect-error
|
||||
updateCustomers(
|
||||
customerId: string,
|
||||
data: CustomerTypes.CustomerUpdatableFields,
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerDTO>
|
||||
update(
|
||||
updateCustomers(
|
||||
customerIds: string[],
|
||||
data: CustomerTypes.CustomerUpdatableFields,
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerDTO[]>
|
||||
update(
|
||||
updateCustomers(
|
||||
selector: CustomerTypes.FilterableCustomerProps,
|
||||
data: CustomerTypes.CustomerUpdatableFields,
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerDTO[]>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async update(
|
||||
async updateCustomers(
|
||||
idsOrSelector: string | string[] | CustomerTypes.FilterableCustomerProps,
|
||||
data: CustomerTypes.CustomerUpdatableFields,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -203,18 +198,19 @@ export default class CustomerModuleService<
|
||||
return isString(idsOrSelector) ? serialized[0] : serialized
|
||||
}
|
||||
|
||||
async createCustomerGroup(
|
||||
// @ts-expect-error
|
||||
async createCustomerGroups(
|
||||
dataOrArrayOfData: CustomerTypes.CreateCustomerGroupDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerGroupDTO>
|
||||
|
||||
async createCustomerGroup(
|
||||
async createCustomerGroups(
|
||||
dataOrArrayOfData: CustomerTypes.CreateCustomerGroupDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerGroupDTO[]>
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
async createCustomerGroup(
|
||||
async createCustomerGroups(
|
||||
dataOrArrayOfData:
|
||||
| CustomerTypes.CreateCustomerGroupDTO
|
||||
| CustomerTypes.CreateCustomerGroupDTO[],
|
||||
@@ -232,7 +228,7 @@ export default class CustomerModuleService<
|
||||
})
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
async updateCustomerGroups(
|
||||
groupId: string,
|
||||
data: CustomerTypes.CustomerGroupUpdatableFields,
|
||||
@@ -319,7 +315,7 @@ export default class CustomerModuleService<
|
||||
)
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
return (groupCustomers as unknown as TCustomerGroupCustomer[]).map(
|
||||
return (groupCustomers as unknown as CustomerGroupCustomer[]).map(
|
||||
(gc) => ({ id: gc.id })
|
||||
)
|
||||
}
|
||||
@@ -327,18 +323,18 @@ export default class CustomerModuleService<
|
||||
return { id: groupCustomers.id }
|
||||
}
|
||||
|
||||
// TODO: should be createAddresses to conform to the convention
|
||||
async addAddresses(
|
||||
// @ts-expect-error
|
||||
async createAddresses(
|
||||
addresses: CustomerTypes.CreateCustomerAddressDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerAddressDTO[]>
|
||||
async addAddresses(
|
||||
async createAddresses(
|
||||
address: CustomerTypes.CreateCustomerAddressDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<CustomerTypes.CustomerAddressDTO>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async addAddresses(
|
||||
async createAddresses(
|
||||
data:
|
||||
| CustomerTypes.CreateCustomerAddressDTO
|
||||
| CustomerTypes.CreateCustomerAddressDTO[],
|
||||
@@ -346,7 +342,7 @@ export default class CustomerModuleService<
|
||||
): Promise<
|
||||
CustomerTypes.CustomerAddressDTO | CustomerTypes.CustomerAddressDTO[]
|
||||
> {
|
||||
const addresses = await this.addAddresses_(data, sharedContext)
|
||||
const addresses = await this.createAddresses_(data, sharedContext)
|
||||
|
||||
const serialized = await this.baseRepository_.serialize<
|
||||
CustomerTypes.CustomerAddressDTO[]
|
||||
@@ -360,7 +356,7 @@ export default class CustomerModuleService<
|
||||
}
|
||||
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
private async addAddresses_(
|
||||
private async createAddresses_(
|
||||
data:
|
||||
| CustomerTypes.CreateCustomerAddressDTO
|
||||
| CustomerTypes.CreateCustomerAddressDTO[],
|
||||
@@ -372,7 +368,7 @@ export default class CustomerModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
// @ts-ignore
|
||||
// @ts-expect-error
|
||||
async updateAddresses(
|
||||
addressId: string,
|
||||
data: CustomerTypes.UpdateCustomerAddressDTO,
|
||||
|
||||
Reference in new issue
Block a user