Skip to content

Commit

Permalink
chore: small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Jun 21, 2024
1 parent 8e73005 commit 9f4614e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1,431 deletions.
2 changes: 1 addition & 1 deletion src/v0/destinations/one_signal/transformV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ const trackOrGroupResponseBuilder = (message, { Config }, msgtype) => {
if (properties && allowedProperties && Array.isArray(allowedProperties)) {
allowedProperties.forEach((item) => {
if (typeof properties[item.propertyName] === 'string') {
const tagName = eventAsTags ? `${event}_${[item.propertyName]}` : item.propertyName;
const tagName = event && eventAsTags ? `${event}_${[item.propertyName]}` : item.propertyName;
tags[tagName] = properties[item.propertyName];
}
});
Expand Down
29 changes: 14 additions & 15 deletions src/v0/destinations/one_signal/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,14 @@ const getProductPurchasesDetails = (message) => {
count: product.quantity,
amount: product.amount,
}));
}
return [
removeUndefinedAndNullValues({
sku: properties?.sku,
iso: properties?.iso,
count: properties?.quantity,
amount: properties?.amount,
}),
];
};
const purchaseObject = removeUndefinedAndNullValues({
sku: properties?.sku,
iso: properties?.iso,
count: properties?.quantity,
amount: properties?.amount,
})
return Object.keys(purchaseObject).length>0 ? [purchaseObject]: [];
};

/**
Expand All @@ -148,22 +147,22 @@ const getProductPurchasesDetails = (message) => {
* @param {*} token
* @returns
*/
const constructSubscription = (message, deviceType, token) => {
const constructSubscription = (message, subscriptionType, token, subscriptionField) => {
const deviceModel = message.context?.device?.model;
const deviceOs = message.context?.os?.version;
let deviceSubscriptionPayload = {
type: deviceType,
type: subscriptionType,
token,
device_model: deviceModel,
device_os: deviceOs,
};
// Following mapping is used to do paticular and specific property mapping for subscription
const traits = message.context?.traits || message.traits;
if (traits?.subscriptions?.[deviceType]) {
if (traits?.subscriptions?.[subscriptionField]) {
deviceSubscriptionPayload = {
...deviceSubscriptionPayload,
...constructPayload(
traits.subscriptions[deviceType],
traits.subscriptions[subscriptionField],
mappingConfig[ConfigCategory.SUBSCRIPTION.name],
),
};
Expand Down Expand Up @@ -192,14 +191,14 @@ const getSubscriptions = (message, Config) => {
if (emailDeviceType) {
const token = getFieldValueFromMessage(message, 'email');
if (isDefinedAndNotNullAndNotEmpty(token)) {
subscriptions.push(constructSubscription(message, 'email', token));
subscriptions.push(constructSubscription(message, 'Email', token, 'email'));
}
}
// Creating a device with phone as an identifier
if (smsDeviceType) {
const token = getFieldValueFromMessage(message, 'phone');
if (isDefinedAndNotNullAndNotEmpty(token)) {
subscriptions.push(constructSubscription(message, 'phone', token));
subscriptions.push(constructSubscription(message, 'SMS', token, 'phone'));
}
}
return subscriptions.length > 0 ? subscriptions : undefined;
Expand Down
Loading

0 comments on commit 9f4614e

Please sign in to comment.