UpdateCustomer
Implements UpdateCustomer
Unified Method.
Source
import { assertAuthorized, defineApi, query } from "@vsf-enterprise/unified-api-magento";
import type { Customer } from "@vsf-enterprise/unified-api-magento/ecommerceTypes";
import { getNormalizers } from "@vsf-enterprise/unified-api-magento/udl";
export const updateCustomer = defineApi.updateCustomer(async (context, args) => {
await assertAuthorized(context);
const { email, firstName, lastName } = args;
const { normalizeCustomer } = getNormalizers(context);
if (email) {
// Magento2 API require password to update email
throw { statusCode: 400, message: "Updating email is not supported" };
}
const user = await query(
context.api.updateCustomer({
firstname: firstName,
lastname: lastName,
}),
);
return {
customer: normalizeCustomer(user.updateCustomerV2?.customer as Customer),
};
});