Skip to content

Commit

Permalink
chore: fix search id function
Browse files Browse the repository at this point in the history
  • Loading branch information
am6010 committed Feb 19, 2025
1 parent 5d7247e commit b169c82
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/cdk/v2/destinations/zoho/transformRecordV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const {
validatePresenceOfMandatoryProperties,
formatMultiSelectFieldsV2,
handleDuplicateCheckV2,
searchRecordId,
searchRecordIdV2,
calculateTrigger,
} = require('./utils');
const { REFRESH_TOKEN } = require('../../../../adapters/networkhandler/authConstants');
Expand Down Expand Up @@ -197,10 +197,11 @@ const handleDeletion = async (
input,
fields,
Config,
conConfig,
transformedResponseToBeBatched,
errorResponseList,
) => {
const searchResponse = await searchRecordId(fields, input.metadata, Config);
const searchResponse = await searchRecordIdV2(fields, input.metadata, Config, conConfig);

if (searchResponse.erroneous) {
const error = handleSearchError(searchResponse);
Expand Down Expand Up @@ -255,6 +256,7 @@ const processInput = async (
input,
allFields,
Config,
conConfig,
transformedResponseToBeBatched,
errorResponseList,
);
Expand Down
63 changes: 63 additions & 0 deletions src/cdk/v2/destinations/zoho/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ function transformToURLParams(fields, Config) {
return `${regionBasedEndPoint}/crm/v6/Leads/search?criteria=${criteria}`;
}

function transformToURLParamsV2(fields, Config, object) {
const criteria = Object.entries(fields)
.map(([key, value]) => `(${key}:equals:${escapeAndEncode(value)})`)
.join('and');

const dataCenter = Config.region;
const regionBasedEndPoint = zohoConfig.DATA_CENTRE_BASE_ENDPOINTS_MAP[dataCenter];

return `${regionBasedEndPoint}/crm/v6/${object}/search?criteria=${criteria}`;
}

const searchRecordId = async (fields, metadata, Config) => {
try {
const searchURL = transformToURLParams(fields, Config);
Expand Down Expand Up @@ -197,6 +208,56 @@ const searchRecordId = async (fields, metadata, Config) => {
}
};

const searchRecordIdV2 = async (fields, metadata, Config, conConfig) => {
try {
const { object } = conConfig.destination;
const searchURL = transformToURLParamsV2(fields, Config, object);
const searchResult = await handleHttpRequest(
'get',
searchURL,
{
headers: {
Authorization: `Zoho-oauthtoken ${metadata.secret.accessToken}`,
},
},
{
destType: 'zoho',
feature: 'deleteRecords',
requestMethod: 'GET',
endpointPath: `crm/v6/${object}/search?criteria=`,
module: 'router',
},
);

if (!isHttpStatusSuccess(searchResult.processedResponse.status)) {
return {

Check warning on line 233 in src/cdk/v2/destinations/zoho/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/zoho/utils.js#L233

Added line #L233 was not covered by tests
erroneous: true,
message: searchResult.processedResponse.response,
};
}

if (
searchResult.processedResponse.status === 204 ||
!CommonUtils.isNonEmptyArray(searchResult.processedResponse.response?.data)
) {
return {
erroneous: true,
message: 'No contact is found with record details',
};
}

return {
erroneous: false,
message: searchResult.processedResponse.response.data.map((record) => record.id),
};
} catch (error) {
return {

Check warning on line 254 in src/cdk/v2/destinations/zoho/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/zoho/utils.js#L254

Added line #L254 was not covered by tests
erroneous: true,
message: error.message,
};
}
};

// ref : https://www.zoho.com/crm/developer/docs/api/v6/upsert-records.html#:~:text=The%20trigger%20input%20can%20be%20workflow%2C%20approval%2C%20or%20blueprint.%20If%20the%20trigger%20is%20not%20mentioned%2C%20the%20workflows%2C%20approvals%20and%20blueprints%20related%20to%20the%20API%20will%20get%20executed.%20Enter%20the%20trigger%20value%20as%20%5B%5D%20to%20not%20execute%20the%20workflows.
const calculateTrigger = (trigger) => {
if (trigger === 'Default') {
Expand Down Expand Up @@ -232,7 +293,9 @@ module.exports = {
handleDuplicateCheck,
handleDuplicateCheckV2,
searchRecordId,
searchRecordIdV2,
transformToURLParams,
transformToURLParamsV2,
calculateTrigger,
validateConfigurationIssue,
};

0 comments on commit b169c82

Please sign in to comment.