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

CreateCustomerAddress

Implements CreateCustomerAddress Unified Method.

Source

import { assertAuthorized, defineApi } from "@vsf-enterprise/unified-api-sapcc";

import { getNormalizers } from "@vue-storefront/unified-data-model";

export const createCustomerAddress = defineApi.createCustomerAddress(async (context, args) => {
  assertAuthorized(context);
  const { address } = args;
  const { unnormalizeAddress, normalizeCustomerAddress } = getNormalizers(context);

  const createdAddress = await context.api.createAddress({
    address: unnormalizeAddress(address),
  });

  return {
    address: normalizeCustomerAddress(createdAddress),
  };
});