feat: customer bulk endpoint form managing customer groups (#9761)
Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import { linkCustomerGroupsToCustomerWorkflow } from "@medusajs/core-flows"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
|
||||
import { HttpTypes, LinkMethodRequest } from "@medusajs/framework/types"
|
||||
|
||||
import { refetchCustomer } from "../../helpers"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<LinkMethodRequest>,
|
||||
res: MedusaResponse<HttpTypes.AdminCustomerResponse>
|
||||
) => {
|
||||
const { id } = req.params
|
||||
const { add, remove } = req.validatedBody
|
||||
|
||||
const workflow = linkCustomerGroupsToCustomerWorkflow(req.scope)
|
||||
await workflow.run({
|
||||
input: {
|
||||
id,
|
||||
add,
|
||||
remove,
|
||||
},
|
||||
})
|
||||
|
||||
const customer = await refetchCustomer(
|
||||
id,
|
||||
req.scope,
|
||||
req.remoteQueryConfig.fields
|
||||
)
|
||||
|
||||
res.status(200).json({ customer: customer })
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
validateAndTransformBody,
|
||||
validateAndTransformQuery,
|
||||
} from "@medusajs/framework"
|
||||
import { createLinkBody } from "../../utils/validators"
|
||||
|
||||
export const adminCustomerRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
{
|
||||
@@ -101,4 +102,15 @@ export const adminCustomerRoutesMiddlewares: MiddlewareRoute[] = [
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
method: ["POST"],
|
||||
matcher: "/admin/customers/:id/customer-groups",
|
||||
middlewares: [
|
||||
validateAndTransformBody(createLinkBody()),
|
||||
validateAndTransformQuery(
|
||||
AdminCustomerParams,
|
||||
QueryConfig.retrieveTransformQueryConfig
|
||||
),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user