Skip to content

Commit

Permalink
refactor: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Nov 28, 2023
1 parent ab61fa8 commit 21ac726
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions src/v0/destinations/marketo_static_list/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,22 @@ const processEvent = (event) => {
if (message.properties?.listData?.remove) {
toRemove = getIds(message.properties.listData.remove);
}
if (
(!Array.isArray(toAdd) || toAdd.length === 0) &&
(!Array.isArray(toRemove) || toRemove.length === 0)
) {
if (Array.isArray(toRemove) && toRemove.length > 0) {
const payload = batchResponseBuilder(message, Config, token, toRemove, 'remove');
if (payload) {
response.push(...payload);
}
}
if (Array.isArray(toAdd) && toAdd.length > 0) {
const payload = batchResponseBuilder(message, Config, token, toAdd, 'add');
if (payload) {
response.push(...payload);
}
}
if (response.length === 0) {
throw new InstrumentationError(
'Invalid leadIds format or no leadIds found neither to add nor to remove',
);
} else {
if (Array.isArray(toRemove) && toRemove.length > 0) {
const payload = batchResponseBuilder(message, Config, token, toRemove, 'remove');
if (payload) {
response.push(...payload);
}
}
if (Array.isArray(toAdd) && toAdd.length > 0) {
const payload = batchResponseBuilder(message, Config, token, toAdd, 'add');
if (payload) {
response.push(...payload);
}
}
}
return response;
};
Expand Down

0 comments on commit 21ac726

Please sign in to comment.