Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Push boolean questions (deployment/demo) to Omeda
Browse files Browse the repository at this point in the history
  • Loading branch information
zarathustra323 committed Jan 19, 2022
1 parent 77b8321 commit 8bd00d4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions packages/marko-web-omeda-identity-x/rapid-identify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const gql = require('graphql-tag');
const { get, getAsArray } = require('@parameter1/base-cms-object-path');
const isOmedaDemographicId = require('./external-id/is-demographic-id');
const isDeploymentTypeId = require('./external-id/is-deployment-type-id');

const ALPHA3_CODE = gql`
query GetAlpha3Code($alpha2: String!) {
Expand Down Expand Up @@ -67,6 +68,24 @@ module.exports = async ({
};
});

const deploymentTypes = [];
getAsArray(appUser, 'customBooleanFieldAnswers').forEach((boolean) => {
const { field, hasAnswered } = boolean;
const { externalId } = field;
if (!field.active || !externalId || !hasAnswered) return;

const { identifier } = field.externalId;
const id = parseInt(identifier.value, 10);

if (isOmedaDemographicId({ externalId, brandKey })) {
demographics.push({ id, values: [`${boolean.value}`] });
}

if (isDeploymentTypeId({ externalId, brandKey })) {
deploymentTypes.push({ id, optedIn: boolean.answer });
}
});

const { id, encryptedCustomerId } = await omedaRapidIdentify({
email: appUser.email,
productId,
Expand All @@ -78,6 +97,7 @@ module.exports = async ({
...(regionCode && { regionCode }),
...(postalCode && { postalCode }),
...(demographics.length && { demographics }),
...(deploymentTypes.length && { deploymentTypes }),
...(promoCode && { promoCode }),
});

Expand Down
4 changes: 4 additions & 0 deletions packages/marko-web-omeda/rapid-identify.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ module.exports = async (omedaGraphQLClient, {
countryCode,
postalCode,

// deprecated, use `deploymentTypes` instead
deploymentTypeIds,

deploymentTypes,
demographics,

promoCode,
Expand All @@ -39,6 +42,7 @@ module.exports = async (omedaGraphQLClient, {
...(postalCode && { postalCode }),

...(isArray(deploymentTypeIds) && deploymentTypeIds.length && { deploymentTypeIds }),
...(isArray(deploymentTypes) && deploymentTypes.length && { deploymentTypes }),
...(isArray(demographics) && demographics.length && { demographics }),

...(promoCode && { promoCode }),
Expand Down

0 comments on commit 8bd00d4

Please sign in to comment.