Skip to content

Commit

Permalink
chore: addressed comments+1
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Oct 30, 2023
1 parent ffcbfcf commit e650cbd
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,18 +326,15 @@ const getDefaultResponseData = (message, rawPayload, evType, groupInfo) => {
return { groups, rawPayload };
};
const getResponseData = (evType, destination, rawPayload, message, groupInfo) => {
let endpoint = defaultEndpoint(destination.Config);
let groups;

switch (evType) {
case EventType.IDENTIFY:
endpoint = defaultEndpoint(destination.Config);
// event_type for identify event is $identify
rawPayload.event_type = IDENTIFY_AM;
identifyBuilder(message, destination, rawPayload);
break;
case EventType.GROUP:
endpoint = defaultEndpoint(destination.Config);
// event_type for identify event is $identify
rawPayload.event_type = IDENTIFY_AM;
// for Rudder group call, update the user_properties with group info
Expand All @@ -348,12 +345,11 @@ const getResponseData = (evType, destination, rawPayload, message, groupInfo) =>
}
break;
case EventType.ALIAS:
endpoint = aliasEndpoint(destination.Config);
break;
default:
({ groups, rawPayload } = getDefaultResponseData(message, rawPayload, evType, groupInfo));
}
return { endpoint, rawPayload, groups };
return { rawPayload, groups };
};

const buildPayloadForMobileChannel = (message, destination, payload) => {
Expand Down Expand Up @@ -451,7 +447,7 @@ const nonAliasResponsebuilder = (
if (evType === EventType.GROUP && groupInfo) {
groupResponse.method = defaultPostRequestConfig.requestMethod;
groupResponse.endpoint = groupEndpoint(destination.Config);
let groupPayload = Object.assign(groupInfo);
let groupPayload = cloneDeep(groupInfo);
groupResponse.userId = message.anonymousId;
groupPayload = removeUndefinedValues(groupPayload);
groupResponse.body.FORM = {
Expand All @@ -471,7 +467,7 @@ const responseBuilderSimple = (
mappingJson,
destination,
) => {
let rawPayload = {};
const rawPayload = {};
const respList = [];
const aliasResponse = defaultRequestConfig();
if (
Expand Down Expand Up @@ -517,15 +513,13 @@ const responseBuilderSimple = (
};

const respData = getResponseData(evType, destination, rawPayload, message, groupInfo);
const { groups } = respData;
// eslint-disable-next-line prefer-const
({ rawPayload } = respData);
const { groups, rawPayload: updatedRawPayload } = respData;

// for https://api.amplitude.com/2/httpapi , pass the "groups" key
// refer (1.) for passing "groups" for Rudder group call
// https://developers.amplitude.com/docs/http-api-v2#schemaevent
set(rawPayload, 'groups', groups);
let payload = removeUndefinedValues(rawPayload);
set(updatedRawPayload, 'groups', groups);
let payload = removeUndefinedValues(updatedRawPayload);
let unmapUserId;
if (evType === EventType.ALIAS) {
// By default (1.), Alias config file populates user_id and global_user_id
Expand Down Expand Up @@ -836,7 +830,7 @@ const getBatchEvents = (message, destination, metadata, batchEventResponse) => {
if (batchEventArray.length === 0) {
if (JSON.stringify(incomingMessageJSON).length < AMBatchSizeLimit) {
delete message.body.JSON.options;
batchEventResponse = Object.assign(batchEventResponse, {
Object.assign(batchEventResponse, {
batchedRequest: message,
});

Expand Down Expand Up @@ -904,7 +898,7 @@ const batch = (destEvents) => {
*/
if (checkForJSONAndUserIdLengthAndDeviceId(jsonBody, userId, deviceId)) {
response = defaultBatchRequestConfig();
response = Object.assign(response, { batchedRequest: message });
Object.assign(response, { batchedRequest: message });
response.metadata = [metadata];
response.destination = destinationObject;
respList.push(response);
Expand Down

0 comments on commit e650cbd

Please sign in to comment.