The Vue Storefront Essentials Course is now available! Learn More
UpdateCustomer

UpdateCustomer

Implements UpdateCustomer Unified Method.

Source

import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sapcc";
import { getNormalizers } from "@vue-storefront/unified-data-model";

export const updateCustomer = defineApi.updateCustomer(async (context, args) => {
  assertAuthorized(context);

  const { email, firstName, lastName } = args;
  const { normalizeCustomer } = getNormalizers(context);

  const user = await context.api.updateAndGetUser({
    user: {
      firstName,
      lastName,
      uid: email,
    },
  });

  return {
    customer: normalizeCustomer(user),
  };
});