Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration with leadsquared #649 #671

Conversation

Iamsidar07
Copy link
Contributor

@Iamsidar07 Iamsidar07 commented Aug 20, 2024

fixes #649

Integrated the following objects:

  1. Task
  2. Deal
  3. Contact
  4. Engagement

Summary by CodeRabbit

  • New Features

    • Introduced integration with LeadSquared CRM for managing contacts, deals, engagements, and tasks.
    • Added functionality to add and synchronize contacts, deals, engagements, and tasks with LeadSquared.
    • Implemented mapping classes for transforming data between unified CRM formats and LeadSquared.
  • Type Definitions

    • Added comprehensive type definitions for contacts, deals, engagements, and tasks to enhance type safety and clarity in interactions.
  • Documentation

    • Improved documentation for new service classes and their methods to support user understanding of the LeadSquared integration features.

@rflihxyz
Copy link
Contributor

Qovery Preview

Qovery can create a Preview Environment for this PR.
To trigger its creation, please post a comment with one of the following command.

Command Blueprint environment
/qovery preview 783d0240-ec38-4387-a9a9-8e225f1bd3e1 dev
/qovery preview {all|UUID1,UUID2,...} To preview multiple environments

This comment has been generated from Qovery AI 🤖.
Below, a word from its wisdom :

One day they will all understand

Copy link

changeset-bot bot commented Aug 20, 2024

⚠️ No Changeset found

Latest commit: 33154c0

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@CLAassistant
Copy link

CLAassistant commented Aug 20, 2024

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

coderabbitai bot commented Aug 20, 2024

Walkthrough

Walkthrough

The integration with LeadSquared CRM introduces new services and mappers for managing contacts, deals, tasks, and engagements. Each service implements a corresponding interface, providing methods for adding and synchronizing data with LeadSquared. TypeScript types are defined to enhance type safety, while utility methods facilitate data transformation and API interaction. This comprehensive integration supports both reading and writing data, enriching the CRM capabilities significantly.

Changes

Files Change Summary
packages/api/src/crm/contact/services/leadsquared/*.ts Introduced LeadSquaredService and LeadSquaredContactMapper for contact management and data transformation. New methods for adding and synchronizing contacts. New types for contact data.
packages/api/src/crm/deal/services/leadsquared/*.ts Introduced LeadSquaredService and LeadSquaredDealMapper for deal management and data transformation. New methods for adding and synchronizing deals. New types for deal data.
packages/api/src/crm/engagement/services/leadsquared/*.ts Introduced LeadSquaredService and LeadSquaredEngagementMapper for engagement management and data transformation. New methods for adding and synchronizing engagements. New types for engagement data.
packages/api/src/crm/task/services/leadsquared/*.ts Introduced LeadSquaredService and LeadSquaredTaskMapper for task management and data transformation. New methods for adding and synchronizing tasks. New types for task data.

Assessment against linked issues

Objective Addressed Explanation
Integrate with LeadSquared CRM for contacts, deals, tasks, and engagements. (#649)
Facilitate reading and writing of data for the integrated objects. (#649)
Provide necessary API interactions as per LeadSquared documentation. (#649)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 27

Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

Commits

Files that changed from the base of the PR and between 66be9ac and 33154c0.

Files selected for processing (12)
  • packages/api/src/crm/contact/services/leadsquared/index.ts (1 hunks)
  • packages/api/src/crm/contact/services/leadsquared/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/services/leadsquared/types.ts (1 hunks)
  • packages/api/src/crm/deal/services/leadsquared/index.ts (1 hunks)
  • packages/api/src/crm/deal/services/leadsquared/mappers.ts (1 hunks)
  • packages/api/src/crm/deal/services/leadsquared/types.ts (1 hunks)
  • packages/api/src/crm/engagement/services/leadsquared/index.ts (1 hunks)
  • packages/api/src/crm/engagement/services/leadsquared/mappers.ts (1 hunks)
  • packages/api/src/crm/engagement/services/leadsquared/types.ts (1 hunks)
  • packages/api/src/crm/task/services/leadsquared/index.ts (1 hunks)
  • packages/api/src/crm/task/services/leadsquared/mappers.ts (1 hunks)
  • packages/api/src/crm/task/services/leadsquared/types.ts (1 hunks)
Additional context used
Biome
packages/api/src/crm/task/services/leadsquared/index.ts

[error] 22-22: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 66-66: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 112-112: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/crm/deal/services/leadsquared/index.ts

[error] 23-23: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 75-75: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 114-114: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/crm/contact/services/leadsquared/index.ts

[error] 27-27: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 81-81: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 137-137: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

packages/api/src/crm/contact/services/leadsquared/mappers.ts

[error] 44-44: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 112-112: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 123-123: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 129-129: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 135-135: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 141-141: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/api/src/crm/engagement/services/leadsquared/index.ts

[error] 30-30: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)


[error] 71-71: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 107-107: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 150-150: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 185-185: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 226-226: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 271-271: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)


[error] 294-294: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Additional comments not posted (33)
packages/api/src/crm/task/services/leadsquared/types.ts (4)

1-3: LGTM!

The KeyValuePair interface is well-defined and allows flexibility for key-value pairs.


5-38: LGTM!

The LeadSquaredTask interface is well-structured and uses string literals effectively for specific fields, enhancing type safety.


40-40: LGTM!

The LeadSquaredTaskInput type correctly uses Partial to allow optional fields.


41-41: LGTM!

The LeadSquaredTaskOutput type, being identical to LeadSquaredTaskInput, is consistent and flexible for handling outputs.

packages/api/src/crm/deal/services/leadsquared/types.ts (4)

1-4: LGTM!

The LeadDetail type is well-defined and correctly typed.


6-9: LGTM!

The Field type is well-defined and correctly typed.


22-25: LGTM!

The LeadSquaredDealInput type is comprehensive and correctly typed.


27-51: LGTM!

The LeadSquaredDealOutput type is comprehensive and correctly typed.

packages/api/src/crm/contact/services/leadsquared/types.ts (4)

1-96: LGTM!

The LeadSquaredContact type is comprehensive and well-documented with comments for field descriptions.


98-105: LGTM!

The LeadSquaredContactResponse type is well-defined and correctly typed.


107-108: LGTM!

The LeadSquaredContactInput type is comprehensive and correctly typed.


108-108: LGTM!

The LeadSquaredContactOutput type is comprehensive and correctly typed.

packages/api/src/crm/engagement/services/leadsquared/types.ts (8)

1-3: LGTM!

The KeyValuePair interface is well-defined and allows flexibility for key-value pairs.


5-26: LGTM!

The LeadSquaredEngagementCall type is well-structured and uses string literals effectively for specific fields, enhancing type safety.


28-37: LGTM!

The SenderType and RecipientType types are well-defined and enhance type safety with string literals.


39-61: LGTM!

The LeadSquaredEngagementEmail type is comprehensive and correctly typed.


63-65: LGTM!

The LeadSquaredEngagementEmailInput type is comprehensive and correctly typed.


65-65: LGTM!

The LeadSquaredEngagementEmailOutput type is comprehensive and correctly typed.


67-101: LGTM!

The LeadSquaredEngagementMeeting type is comprehensive and correctly typed.


102-115: LGTM!

The types for LeadSquaredEngagementCallInput, LeadSquaredEngagementMeetingInput, LeadSquaredEngagementMeetingOutput, LeadSquaredEngagementOutput, and LeadSquaredEngagementInput are comprehensive and correctly typed.

packages/api/src/crm/deal/services/leadsquared/mappers.ts (3)

24-65: LGTM!

The desunify function correctly maps unified CRM deal input to LeadSquared-specific input.


67-88: LGTM!

The unify function correctly handles both single and multiple LeadSquared deal outputs.


90-145: LGTM!

The mapSingleDealToUnified function accurately maps LeadSquared deal output to unified CRM deal output, handling custom field mappings and stage ingestion.

packages/api/src/crm/task/services/leadsquared/mappers.ts (3)

24-85: LGTM!

The desunify function correctly maps unified CRM task input to LeadSquared-specific input.


87-108: LGTM!

The unify function correctly handles both single and multiple LeadSquared task outputs.


110-177: LGTM!

The mapSingleTaskToUnified function accurately maps LeadSquared task output to unified CRM task output, handling custom field mappings and related entity associations.

packages/api/src/crm/contact/services/leadsquared/mappers.ts (1)

96-175: LGTM!

The mapSingleContactToUnified function accurately maps LeadSquared contact output to unified CRM contact output, handling custom field mappings and contact details.

Tools
Biome

[error] 112-112: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 123-123: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 129-129: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 135-135: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


[error] 141-141: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

packages/api/src/crm/engagement/services/leadsquared/mappers.ts (6)

22-32: Constructor implementation looks good.

The constructor correctly initializes dependencies and registers the mapper with the registry.


44-63: Desunify method implementation looks good.

The method correctly handles different engagement types and returns the appropriate LeadSquared-specific format.


65-119: DesunifyEmail method implementation looks good.

The method correctly transforms unified email engagement inputs into LeadSquared-specific format, including optional mappings and ID conversions.


121-187: DesunifyMeeting method implementation looks good.

The method correctly transforms unified meeting engagement inputs into LeadSquared-specific format, including optional mappings and ID conversions.


241-269: Unify method implementation looks good.

The method correctly handles different engagement types and returns the appropriate unified format.


271-363: UnifyMeeting and UnifyEmail methods implementation looks good.

Both methods correctly transform LeadSquared-specific outputs into a unified format, including optional mappings and ID conversions.

Comment on lines +11 to +20
type Opportunity = {
Filelds: Field[];
OpportunityEventCode: number;
OpportunityNote?: string;
OpportunityDateTime?: string; //date and time is in the yyyy-mm-dd hh:mm:ss format.
OverwriteFields?: boolean;
UpdateEmptyFields?: boolean;
DoNotPostDuplicateActivity?: boolean;
DoNotChangeOwner?: boolean;
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix typo in property name.

The property Filelds should be corrected to Fields.

Fix the typo as follows:

-  Filelds: Field[];
+  Fields: Field[];
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
type Opportunity = {
Filelds: Field[];
OpportunityEventCode: number;
OpportunityNote?: string;
OpportunityDateTime?: string; //date and time is in the yyyy-mm-dd hh:mm:ss format.
OverwriteFields?: boolean;
UpdateEmptyFields?: boolean;
DoNotPostDuplicateActivity?: boolean;
DoNotChangeOwner?: boolean;
};
type Opportunity = {
Fields: Field[];
OpportunityEventCode: number;
OpportunityNote?: string;
OpportunityDateTime?: string; //date and time is in the yyyy-mm-dd hh:mm:ss format.
OverwriteFields?: boolean;
UpdateEmptyFields?: boolean;
DoNotPostDuplicateActivity?: boolean;
DoNotChangeOwner?: boolean;
};

Comment on lines +111 to +113
} catch (error) {
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch block.

The catch block that only rethrows the original error is unnecessary and can be removed.

Remove the catch block as follows:

-    } catch (error) {
-      throw error;
-    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
throw error;
}
Tools
Biome

[error] 112-112: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +21 to +22
this.logger.setContext(
CrmObject.task.toUpperCase() + ':' + LeadSquaredService.name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use template literals instead of string concatenation.

Replace the string concatenation with a template literal for better readability.

Fix the code as follows:

-    CrmObject.task.toUpperCase() + ':' + LeadSquaredService.name,
+    `${CrmObject.task.toUpperCase()}:${LeadSquaredService.name}`,
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
this.logger.setContext(
CrmObject.task.toUpperCase() + ':' + LeadSquaredService.name,
this.logger.setContext(
`${CrmObject.task.toUpperCase()}:${LeadSquaredService.name}`,
Tools
Biome

[error] 22-22: Template literals are preferred over string concatenation.

Unsafe fix: Use a template literal.

(lint/style/useTemplate)

Comment on lines +65 to +67
} catch (error) {
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch block.

The catch block that only rethrows the original error is unnecessary and can be removed.

Remove the catch block as follows:

-    } catch (error) {
-      throw error;
-    }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
throw error;
}
Tools
Biome

[error] 66-66: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

statusCode: 200,
};
} catch (error) {
throw error;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch clause.

The catch clause that only rethrows the original error is unnecessary and can be removed to simplify the code.

- } catch (error) {
-   throw error;
- }
+ }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throw error;
}
Tools
Biome

[error] 114-114: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +270 to +272
} catch (error) {
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch clause.

The catch clause only rethrows the original error, which is unnecessary and can be removed to simplify the code.

Remove the redundant catch clause as follows:

- } catch (error) {
-   throw error;
- }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
throw error;
}
Tools
Biome

[error] 271-271: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +35 to +42
formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = date.getUTCMonth();
const currentDate = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
return `${year}-${month}-${currentDate} ${hours}:${minutes}:${seconds}`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust the month value in date formatting.

The getUTCMonth() method returns a zero-based month index. Add 1 to the month value to get the correct month number.

Fix the month calculation as follows:

- const month = date.getUTCMonth();
+ const month = date.getUTCMonth() + 1;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = date.getUTCMonth();
const currentDate = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
return `${year}-${month}-${currentDate} ${hours}:${minutes}:${seconds}`;
formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const currentDate = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
return `${year}-${month}-${currentDate} ${hours}:${minutes}:${seconds}`;

Comment on lines +70 to +72
} catch (error) {
throw error;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove redundant catch clause.

The catch clause only rethrows the original error, which is unnecessary and can be removed to simplify the code.

Remove the redundant catch clause as follows:

- } catch (error) {
-   throw error;
- }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} catch (error) {
throw error;
}
Tools
Biome

[error] 71-71: The catch clause that only rethrows the original error is redundant.

These unnecessary catch clauses can be confusing. It is recommended to remove them.

(lint/complexity/noUselessCatch)

Comment on lines +189 to +239
private async desunifyCall(
source: UnifiedCrmEngagementInput,
customFieldMappings?: {
slug: string;
remote_id: string;
}[],
): Promise<LeadSquaredEngagementInput> {
const result: LeadSquaredEngagementCallInput = {
Direction: source.direction === 'INBOUND' ? 'Inbound' : 'Outbound',
CallerSource: source.content || '',
LeadId: source.company_id || '',
SourceNumber: '', // todo,
DisplayNumber: '', // todo
DestinationNumber: '', // todo,
};

if (source.start_at && source.end_time) {
const startDate = new Date(source.start_at);
const endDate = new Date(source.end_time);

// Calculate the difference in milliseconds
const diffMilliseconds = endDate.getTime() - startDate.getTime();

// Convert milliseconds to seconds
const durationInSeconds = Math.round(diffMilliseconds / 1000);
result.StartTime = this.formatDate(startDate);
result.EndTime = this.formatDate(endDate);
result.CallDuration = durationInSeconds;
result.Status = 'Answered';
}

if (source.user_id) {
const owner_id = await this.utils.getRemoteIdFromUserUuid(source.user_id);
if (owner_id) {
result.UserId = owner_id;
}
}

if (customFieldMappings && source.field_mappings) {
for (const [k, v] of Object.entries(source.field_mappings)) {
const mapping = customFieldMappings.find(
(mapping) => mapping.slug === k,
);
if (mapping) {
result[mapping.remote_id] = v;
}
}
}

return result;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Address TODO comments in desunifyCall method.

The method includes TODO comments for SourceNumber, DisplayNumber, and DestinationNumber. Ensure these fields are properly handled before deploying.

Would you like me to assist in implementing these fields or open a GitHub issue to track this task?

Comment on lines +34 to +42
formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = date.getUTCMonth();
const currentDate = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
return `${year}-${month}-${currentDate} ${hours}:${minutes}:${seconds}`;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adjust the month value in date formatting.

The getUTCMonth() method returns a zero-based month index. Add 1 to the month value to get the correct month number.

Fix the month calculation as follows:

- const month = date.getUTCMonth();
+ const month = date.getUTCMonth() + 1;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = date.getUTCMonth();
const currentDate = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
return `${year}-${month}-${currentDate} ${hours}:${minutes}:${seconds}`;
}
formatDate(date: Date): string {
const year = date.getUTCFullYear();
const month = date.getUTCMonth() + 1;
const currentDate = date.getUTCDate();
const hours = date.getUTCHours();
const minutes = date.getUTCMinutes();
const seconds = date.getUTCSeconds();
return `${year}-${month}-${currentDate} ${hours}:${minutes}:${seconds}`;
}

@Iamsidar07 Iamsidar07 closed this Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Add integration with: LeadSquared (CRM)
3 participants