Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Contents

+

Table of Contents
stylenone

...

Mapping loyalty offers between Sanity and the Loyalty Engine

Mapping Loyalty Offers Between Sanity and the Loyalty Engine After retrieving all the available offers from both Sanity and the Loyalty Enginesources, you need to map this data to compile get a complete list of offers available to the user. Below there is a simple example in JavaScript demonstrating how to perform this mapping:

Note

This example focuses on the basic data mapping process. It does not include logic related to offer rules, authentication requirements, or error handling. Each implementation should incorporate the necessary logic based on its specific needs.

Code Block
const { liveConfigOffers, sortedSystemwideOffers } = sanityOffers;
const { loyaltyOffersV2 } = loyaltyEngineOffers;

const allAvailableUserOffers = loyaltyOffersV2
  .map(loyaltyOffer => {
    let sanityOffer;

    if (loyaltyOffer.type === 'GLOBAL') {
      sanityOffer = sortedSystemwideOffers.find(
        offer => offer.loyaltyEngineId === loyaltyOffer.id
      );
    } else if (loyaltyOffer.type === 'PERSONALIZED') {
      sanityOffer = liveConfigOffers.find(
        offer => offer.loyaltyEngineId === loyaltyOffer.id
      );
    }

    if (sanityOffer) {
      return sanityOffer;
    }
  })
  .filter(offer => offer !== undefined);

...