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:
Frane Polić
2024-10-25 11:55:57 +02:00
committed by GitHub
parent bb6d7c6641
commit 259d050e53
12 changed files with 271 additions and 32 deletions

View File

@@ -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 })
}

View File

@@ -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
),
],
},
]