feat(customer): add customer group customer management (#6276)

**What**
- GET /admin/customer-groups/:id/customers
- POST /admin/customer-groups/:id/customers/batch
- POST /admin/customer-groups/:id/customers/remove

Workflows
This commit is contained in:
Sebastian Rindom
2024-01-31 10:24:22 +00:00
committed by GitHub
parent 36ec3ea3aa
commit f41877ef61
14 changed files with 522 additions and 12 deletions
@@ -0,0 +1,29 @@
import { GroupCustomerPair, ICustomerModuleService } from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export const createCustomerGroupCustomersStepId =
"create-customer-group-customers"
export const createCustomerGroupCustomersStep = createStep(
createCustomerGroupCustomersStepId,
async (data: GroupCustomerPair[], { container }) => {
const service = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
const groupPairs = await service.addCustomerToGroup(data)
return new StepResponse(groupPairs, data)
},
async (groupPairs, { container }) => {
if (!groupPairs?.length) {
return
}
const service = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
await service.removeCustomerFromGroup(groupPairs)
}
)
@@ -0,0 +1,28 @@
import { GroupCustomerPair, ICustomerModuleService } from "@medusajs/types"
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
export const deleteCustomerGroupCustomersStepId =
"delete-customer-group-customers"
export const deleteCustomerGroupCustomersStep = createStep(
deleteCustomerGroupCustomersStepId,
async (data: GroupCustomerPair[], { container }) => {
const service = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
await service.removeCustomerFromGroup(data)
return new StepResponse(void 0, data)
},
async (groupPairs, { container }) => {
if (!groupPairs?.length) {
return
}
const service = container.resolve<ICustomerModuleService>(
ModuleRegistrationName.CUSTOMER
)
await service.addCustomerToGroup(groupPairs)
}
)
@@ -1,3 +1,5 @@
export * from "./update-customer-groups"
export * from "./delete-customer-groups"
export * from "./create-customer-groups"
export * from "./create-customer-group-customers"
export * from "./delete-customer-group-customers"
@@ -0,0 +1,14 @@
import { GroupCustomerPair } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { createCustomerGroupCustomersStep } from "../steps"
type WorkflowInput = { groupCustomers: GroupCustomerPair[] }
export const createCustomerGroupCustomersWorkflowId =
"create-customer-group-customers"
export const createCustomerGroupCustomersWorkflow = createWorkflow(
createCustomerGroupCustomersWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<{ id: string }[]> => {
return createCustomerGroupCustomersStep(input.groupCustomers)
}
)
@@ -0,0 +1,14 @@
import { GroupCustomerPair } from "@medusajs/types"
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
import { deleteCustomerGroupCustomersStep } from "../steps"
type WorkflowInput = { groupCustomers: GroupCustomerPair[] }
export const deleteCustomerGroupCustomersWorkflowId =
"delete-customer-group-customers"
export const deleteCustomerGroupCustomersWorkflow = createWorkflow(
deleteCustomerGroupCustomersWorkflowId,
(input: WorkflowData<WorkflowInput>): WorkflowData<void> => {
return deleteCustomerGroupCustomersStep(input.groupCustomers)
}
)
@@ -1,3 +1,5 @@
export * from "./update-customer-groups"
export * from "./delete-customer-groups"
export * from "./create-customer-groups"
export * from "./create-customer-group-customers"
export * from "./delete-customer-group-customers"