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

Improved synchronization service for all entities. #336

Closed
wants to merge 2 commits into from

Conversation

mit-27
Copy link
Contributor

@mit-27 mit-27 commented Mar 28, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced integration capabilities by adding a remote_id field across various CRM and ticketing services for better synchronization and mapping of company, contact, deal, engagement, note, stage, task, user, account, comment, contact, tag, team, and ticket entities.
  • Refactor

    • Optimized synchronization services by removing redundant ID array creations and directly utilizing the newly introduced remote_id for identifying and saving entities in the database.
    • Improved code readability and maintainability across several modules with adjustments in logic and formatting.
  • Bug Fixes

    • Corrected an indentation and semantic error in the ticketing user service, ensuring accurate data mapping and assignment.

Copy link

changeset-bot bot commented Mar 28, 2024

⚠️ No Changeset found

Latest commit: 8686a3c

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

Copy link

vercel bot commented Mar 28, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
panora-client-ts ❌ Failed (Inspect) Mar 29, 2024 3:55am

Copy link
Contributor

coderabbitai bot commented Mar 28, 2024

Walkthrough

The changes involve updating various service mappers and sync services in the API to include a remote_id field in the returned objects for different entities like companies, contacts, deals, engagements, notes, stages, tasks, users, accounts, comments, tickets, and teams. This addition aims to improve object identification and synchronization processes. Additionally, adjustments have been made to the logic for assigning originId based on these remote_id fields to streamline data handling and storage mechanisms.

Changes

File Pattern Change Summary
.../crm/* Removed array creation based on sourceObject; Modified originId assignment to use object.remote_id.
.../ticketing/* Removed array creation based on sourceObject; Modified originId assignment to use object.remote_id.

Assessment against linked issues

Objective Addressed Explanation
Enhance sync.services.ts to extract IDs of objects and setting the remote_ids (#332)

Possibly related issues

  • PAN-50: The changes align with the objective of adding a remote_id attribute to all relevant objects, ensuring proper population and usage across the system.

Poem

In the realm where data thrives,
A rabbit with code now jives,
Adding remote_id far and wide,
Synchronizing with pride.
🐇📊 Data flows, systems unite,
Guided by IDs shining bright.

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-tests 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 tests 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 tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

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

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 14

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2449e9f and a3b38b5.
Files selected for processing (60)
  • packages/api/src/crm/company/services/attio/mappers.ts (2 hunks)
  • packages/api/src/crm/company/services/hubspot/mappers.ts (2 hunks)
  • packages/api/src/crm/company/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/company/services/zendesk/mappers.ts (2 hunks)
  • packages/api/src/crm/company/services/zoho/mappers.ts (1 hunks)
  • packages/api/src/crm/company/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/contact/services/attio/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/services/freshsales/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/services/hubspot/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/services/zoho/mappers.ts (1 hunks)
  • packages/api/src/crm/contact/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/deal/services/hubspot/mappers.ts (1 hunks)
  • packages/api/src/crm/deal/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/deal/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/deal/services/zoho/mappers.ts (1 hunks)
  • packages/api/src/crm/deal/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/engagement/services/hubspot/mappers.ts (4 hunks)
  • packages/api/src/crm/engagement/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/engagement/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/engagement/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/note/services/hubspot/mappers.ts (1 hunks)
  • packages/api/src/crm/note/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/note/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/note/services/zoho/mappers.ts (1 hunks)
  • packages/api/src/crm/note/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/stage/services/hubspot/mappers.ts (1 hunks)
  • packages/api/src/crm/stage/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/stage/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/stage/sync/sync.service.ts (3 hunks)
  • packages/api/src/crm/task/services/hubspot/mappers.ts (2 hunks)
  • packages/api/src/crm/task/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/task/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/task/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/user/services/hubspot/mappers.ts (1 hunks)
  • packages/api/src/crm/user/services/pipedrive/mappers.ts (1 hunks)
  • packages/api/src/crm/user/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/crm/user/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/account/services/front/mappers.ts (1 hunks)
  • packages/api/src/ticketing/account/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/account/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/comment/services/front/mappers.ts (1 hunks)
  • packages/api/src/ticketing/comment/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/comment/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/contact/services/front/mappers.ts (1 hunks)
  • packages/api/src/ticketing/contact/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/contact/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/tag/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/tag/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/team/services/front/mappers.ts (1 hunks)
  • packages/api/src/ticketing/team/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/team/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/ticket/services/front/mappers.ts (2 hunks)
  • packages/api/src/ticketing/ticket/services/hubspot/mappers.ts (1 hunks)
  • packages/api/src/ticketing/ticket/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/ticket/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/user/services/front/mappers.ts (1 hunks)
  • packages/api/src/ticketing/user/services/zendesk/mappers.ts (1 hunks)
  • packages/api/src/ticketing/user/sync/sync.service.ts (2 hunks)
Additional comments (53)
packages/api/src/ticketing/team/services/front/mappers.ts (1)
  • 42-42: The addition of remote_id: team.id aligns with the PR objectives and should ensure better synchronization by directly linking the original source objects with their unified counterparts. Please verify that the type of team.id is consistent with the expected type for remote_id to avoid any type mismatch issues.
packages/api/src/ticketing/team/services/zendesk/mappers.ts (1)
  • 42-42: Setting remote_id by concatenating team.id with an empty string ensures it's treated as a string. This change aligns with the PR objectives. If team.id is always a string, the concatenation might be unnecessary, but if it's for consistency or type assurance across different services, it's understandable.
packages/api/src/ticketing/account/services/zendesk/mappers.ts (1)
  • 42-42: The inclusion of remote_id: account.id + "" ensures remote_id is treated as a string, aligning with the PR's goal of improving synchronization. As with the previous files, if the concatenation is for type assurance or consistency, it's a sensible approach.
packages/api/src/crm/stage/services/zendesk/mappers.ts (1)
  • 49-49: Adding remote_id: stage.id + "" for stage mapping is consistent with the PR's objectives and the approach taken in other mappers. This ensures remote_id is always treated as a string, contributing to the system's data integrity.
packages/api/src/crm/stage/services/hubspot/mappers.ts (1)
  • 47-47: Directly setting remote_id: stage.id in the Hubspot stage mapper simplifies the implementation and aligns with the PR's objectives. This approach suggests stage.id is already in the desired format, which is beneficial for consistency and simplicity.
packages/api/src/crm/user/services/hubspot/mappers.ts (1)
  • 48-48: Setting remote_id: user.id directly in the Hubspot user mapper aligns with the PR's objectives, ensuring a straightforward and consistent mapping process. This approach indicates that user.id is in the appropriate format, simplifying the implementation.
packages/api/src/crm/stage/services/pipedrive/mappers.ts (1)
  • 49-49: The inclusion of remote_id: stage.id + "" in the Pipedrive stage mapper ensures remote_id is treated as a string, aligning with the PR's objectives. This concatenation approach, used for consistency or type assurance, is understandable.
packages/api/src/ticketing/user/services/zendesk/mappers.ts (1)
  • 46-46: Adding remote_id: user.id + "" in the Zendesk user mapper is consistent with the PR's objectives, ensuring remote_id is treated as a string. This approach, used across different mappers for consistency or type assurance, is sensible.
packages/api/src/ticketing/user/services/front/mappers.ts (1)
  • 46-46: The addition of the remote_id field correctly aligns with the PR objectives, ensuring the remote_id is set based on the source object's ID.
packages/api/src/ticketing/tag/services/zendesk/mappers.ts (1)
  • 41-41: The addition of the id field with a specific format for UnifiedTagOutput is a significant change. It's important to ensure that this format does not conflict with any existing ID formats and that it's properly documented, especially since it's noted as a temporary measure.

Ensure that the use of this format does not conflict with existing ID management strategies and that it's clearly documented as a temporary measure.

packages/api/src/ticketing/account/services/front/mappers.ts (1)
  • 46-46: The addition of the remote_id field is consistent with the PR objectives, ensuring direct linkage between source and unified objects.
packages/api/src/ticketing/contact/services/zendesk/mappers.ts (1)
  • 46-46: Adding the remote_id field by converting the contact's id to a string is a good practice for ensuring type consistency across the system.
packages/api/src/ticketing/contact/services/front/mappers.ts (1)
  • 52-52: The addition of the remote_id field to the UnifiedContactOutput object is correctly implemented, ensuring a direct link between the source and unified objects.
packages/api/src/crm/user/services/zendesk/mappers.ts (1)
  • 63-63: The addition of the remote_id field, converting the user's id to a string, ensures consistency and proper linkage in the system.
packages/api/src/crm/user/services/pipedrive/mappers.ts (1)
  • 63-63: The addition of the remote_id field to the UnifiedUserOutput object aligns with the PR's objectives, ensuring a direct linkage between source and unified objects.
packages/api/src/crm/deal/services/zoho/mappers.ts (1)
  • 64-65: The comment //TODO - might be wrong deal.Owner suggests uncertainty about the source of remote_id. It's crucial to verify that deal.Owner is the correct property for remote_id to ensure data integrity.
packages/api/src/crm/contact/services/freshsales/mappers.ts (1)
  • 69-69: Consider using String(contact.id) for converting contact.id to a string. It makes the intention clearer than using contact.id + "".
packages/api/src/crm/note/services/hubspot/mappers.ts (1)
  • 92-92: The addition of remote_id with the value of note.id correctly aligns with the PR's objectives to ensure proper synchronization.
packages/api/src/ticketing/ticket/services/hubspot/mappers.ts (1)
  • 67-67: The addition of remote_id with the value of ticket.id is correctly implemented. However, there are existing TODO comments related to name and description fields that should be addressed in future updates.
packages/api/src/ticketing/comment/services/front/mappers.ts (1)
  • 87-87: The addition of remote_id to the res object is correctly implemented and aligns with the PR's objectives for synchronization.
packages/api/src/crm/deal/services/pipedrive/mappers.ts (1)
  • 112-112: The addition of remote_id with the value of deal.id is correctly implemented and aligns with the PR's objectives to ensure proper synchronization.
packages/api/src/crm/company/services/zoho/mappers.ts (1)
  • 73-73: The addition of remote_id to the return object is correctly implemented and aligns with the PR's objectives for synchronization.
packages/api/src/crm/deal/services/hubspot/mappers.ts (1)
  • 103-103: The addition of remote_id with the value of deal.id is correctly implemented. However, there are existing TODO comments related to stage_id and other fields that should be addressed in future updates.
packages/api/src/crm/note/services/zendesk/mappers.ts (1)
  • 117-117: The addition of the remote_id field in the mapSingleNoteToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/crm/contact/services/hubspot/mappers.ts (1)
  • 95-96: The addition of the remote_id field in the mapSingleContactToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/ticketing/comment/services/zendesk/mappers.ts (1)
  • 98-98: The addition of the remote_id field in the mapSingleCommentToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/crm/note/services/pipedrive/mappers.ts (1)
  • 133-133: The addition of the remote_id field in the mapSingleNoteToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/crm/deal/services/zendesk/mappers.ts (1)
  • 125-125: The addition of the remote_id field in the mapSingleDealToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/crm/company/services/pipedrive/mappers.ts (1)
  • 93-93: The addition of the remote_id field in the mapSingleCompanyToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/ticketing/ticket/services/front/mappers.ts (1)
  • 118-118: The addition of the remote_id field in the mapSingleTicketToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/crm/contact/services/zoho/mappers.ts (1)
  • 121-121: The addition of the remote_id field in the mapSingleContactToUnified method correctly implements the PR's objective to ensure remote_id is set based on the source object's ID. This change enhances the synchronization process by directly linking the original source objects with their unified counterparts.
packages/api/src/crm/task/services/zendesk/mappers.ts (1)
  • 138-138: The addition of remote_id: task.id, in the unify method correctly implements the PR's objective by ensuring the remote_id is set based on the source object's ID. This change should streamline the synchronization process as intended.
packages/api/src/crm/company/services/hubspot/mappers.ts (1)
  • 112-112: Adding remote_id: company.id, and setting a placeholder value for number_of_employees in the unify method aligns with the PR's objective. However, ensure that the placeholder for number_of_employees is eventually replaced with actual logic to retrieve the correct value.
packages/api/src/crm/task/services/pipedrive/mappers.ts (2)
  • 136-136: Adding remote_id: task.id, in the unify method correctly implements the PR's objective by ensuring the remote_id is set based on the source object's ID. This change should streamline the synchronization process as intended.
  • 140-141: The adjustment in formatting for the due_date assignment enhances readability and clarity. This change ensures that the due_date is correctly handled and assigned, aligning with the PR's objective to improve data integrity.
packages/api/src/crm/contact/services/pipedrive/mappers.ts (1)
  • 124-124: The addition of remote_id: contact.id, in the unify method correctly implements the PR's objective by ensuring the remote_id is set based on the source object's ID. This change should streamline the synchronization process as intended.
packages/api/src/crm/task/services/hubspot/mappers.ts (1)
  • 94-94: Adding remote_id: task.id, in the unify method correctly implements the PR's objective by ensuring the remote_id is set based on the source object's ID. This change should streamline the synchronization process as intended.
packages/api/src/crm/engagement/services/zendesk/mappers.ts (1)
  • 141-141: The addition of remote_id: engagement.id, in the unify method correctly implements the PR's objective by ensuring the remote_id is set based on the source object's ID. This change should streamline the synchronization process as intended.
packages/api/src/crm/contact/services/zendesk/mappers.ts (1)
  • 135-135: The addition of remote_id: contact.id + "", in the unify method correctly implements the PR's objective. However, the concatenation operation to convert contact.id to a string seems unnecessary if contact.id is already a string. If contact.id is not a string, this approach is valid, but it would be more clear to use a more explicit conversion method.

Consider using String(contact.id) for explicit conversion to a string if necessary.

packages/api/src/crm/company/services/zendesk/mappers.ts (2)
  • 14-14: The TODO comment indicates that Zendesk does not have a Company object, which raises questions about the implementation of the ZendeskCompanyMapper. It's crucial to ensure that the mapping logic aligns with the capabilities and limitations of the Zendesk API.
  • 140-140: Adding remote_id: company.id, in the unify method correctly implements the PR's objective by ensuring the remote_id is set based on the source object's ID. This change should streamline the synchronization process as intended.
packages/api/src/crm/contact/services/attio/mappers.ts (2)
  • 120-120: Adding a console.log statement directly into production code can lead to potential performance issues and cluttered log files, especially if the log is not providing critical information.

Consider removing the console.log statement or replacing it with a more structured logging approach that allows for log level control.

  • 123-123: The addition of remote_id directly addresses the issue of undefined or null remote_ids by ensuring that the ID is extracted and assigned during the unification process.

This change effectively streamlines the synchronization process and enhances data integrity.

packages/api/src/ticketing/ticket/services/zendesk/mappers.ts (1)
  • 146-146: The addition of remote_id to the UnifiedTicketOutput object is a crucial improvement.

This change ensures that the original ticket ID from Zendesk is preserved in the unified object, enhancing traceability and data integrity.

packages/api/src/crm/company/services/attio/mappers.ts (1)
  • 144-144: The addition of remote_id directly from company.id?.record_id is a significant improvement.

This ensures that the original company ID from Attio is preserved in the unified object, which is crucial for maintaining data integrity and traceability.

packages/api/src/crm/engagement/services/pipedrive/mappers.ts (1)
  • 177-177: The addition of remote_id to the unified engagement object is a positive change.

This ensures that the original engagement ID from Pipedrive is accurately reflected in the unified object, enhancing data integrity and traceability.

packages/api/src/crm/deal/sync/sync.service.ts (1)
  • 181-181: The assignment of originId directly from deal.remote_id is correct and aligns with the intended changes described in the PR objectives. This approach simplifies the logic by eliminating the need for a separate array to store deal IDs.
packages/api/src/crm/engagement/services/hubspot/mappers.ts (4)
  • 194-195: The union types for HubspotEngagementMeetingOutput have been adjusted. This change is approved as it seems to correct the type to allow for both single and array inputs, enhancing the flexibility of the unifyMeeting method.
  • 201-202: Similarly, the union types for HubspotEngagementEmailOutput have been adjusted to allow for both single and array inputs. This is a positive change that increases the method's versatility in handling different input types.
  • 299-299: The addition of remote_id mapping for engagement ID in the mapSingleEngagementCallToUnified method is a crucial improvement. It directly addresses the PR's objective by ensuring that the remote_id is set based on the source object's ID, which is essential for maintaining a link between the original and unified objects.
  • 382-383: The ternary operator for email direction mapping in the mapSingleEngagementEmailToUnified method has been corrected to map hs_email_direction to 'INBOUND' or 'OUTBOUND', depending on the HubSpot engagement email output. This change is consistent with the PR's objective and improves the accuracy of the direction mapping.
packages/api/src/ticketing/comment/sync/sync.service.ts (1)
  • 209-215: The refinement of opts assignment based on comment.creator_type is a good practice, ensuring that the correct ID is assigned based on the creator type. This change enhances the clarity and maintainability of the code by using a more structured approach to handle different creator types.
packages/api/src/crm/contact/sync/sync.service.ts (1)
  • 196-196: The direct use of contact.remote_id for originId assignment in the saveContactsInDb method is correct and aligns with the PR's objectives. This change ensures that the remote_id is directly used, addressing the issue of previously undefined or null remote_ids.

@@ -201,7 +196,7 @@ export class SyncService implements OnModuleInit {
let stages_results: CrmStage[] = [];
for (let i = 0; i < stages.length; i++) {
const stage = stages[i];
const originId = originIds[i];
const originId = stage.remote_id[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

Using stage.remote_id[i] to access the originId assumes that the index i in the loop over stages directly corresponds to the correct remote_id for each stage. This approach is error-prone because it relies on the order of stages and their remote_ids being perfectly aligned, which might not always be the case, especially if the data undergoes any transformations or filtering that could affect the order.

A more robust approach would be to directly use stage.remote_id without indexing it, ensuring that the correct remote_id is always used for each stage object.

- const originId = stage.remote_id[i];
+ const originId = stage.remote_id;

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.

Suggested change
const originId = stage.remote_id[i];
const originId = stage.remote_id;

originSource: string,
remote_data: Record<string, any>[],
): Promise<CrmEngagement[]> {
try {
let engagements_results: CrmEngagement[] = [];
for (let i = 0; i < engagements.length; i++) {
const engagement = engagements[i];
const originId = originIds[i];
const originId = engagement.remote_id[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the issue identified in the stage synchronization service, using engagement.remote_id[i] to access the originId assumes that the index i in the loop over engagements directly corresponds to the correct remote_id for each engagement. This approach is error-prone because it relies on the order of engagements and their remote_ids being perfectly aligned, which might not always be the case.

A more robust approach would be to directly use engagement.remote_id without indexing it, ensuring that the correct remote_id is always used for each engagement object.

- const originId = engagement.remote_id[i];
+ const originId = engagement.remote_id;

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.

Suggested change
const originId = engagement.remote_id[i];
const originId = engagement.remote_id;

Comment on lines +146 to +147
? 'FORWARDED_EMAIL'
: '',
Copy link
Contributor

Choose a reason for hiding this comment

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

The ternary operator for hs_email_direction has been updated to map source.direction to 'FORWARDED_EMAIL' for 'OUTBOUND' emails. However, this seems to be a logical error since outbound emails should not be mapped to 'FORWARDED_EMAIL'. Instead, they should likely be mapped to a different HubSpot-specific value that accurately represents outbound emails.

-            ? 'FORWARDED_EMAIL'
+            ? 'OUTBOUND_EMAIL' // Assuming 'OUTBOUND_EMAIL' is the correct mapping, please replace with the correct HubSpot value.

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.

Suggested change
? 'FORWARDED_EMAIL'
: '',
? 'OUTBOUND_EMAIL' // Assuming 'OUTBOUND_EMAIL' is the correct mapping, please replace with the correct HubSpot value.
: '',

@@ -192,7 +188,7 @@ export class SyncService implements OnModuleInit {
let comments_results: TicketingComment[] = [];
for (let i = 0; i < comments.length; i++) {
const comment = comments[i];
const originId = originIds[i];
const originId = comment.remote_id[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

The assignment of originId using comment.remote_id[i] is incorrect. The use of the index i with remote_id suggests that remote_id is being treated as an array, which is likely not the case. remote_id should be directly assigned without indexing.

-        const originId = comment.remote_id[i];
+        const originId = comment.remote_id;

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.

Suggested change
const originId = comment.remote_id[i];
const originId = comment.remote_id;

@@ -197,7 +192,7 @@ export class SyncService implements OnModuleInit {
let tags_results: TicketingTag[] = [];
for (let i = 0; i < tags.length; i++) {
const tag = tags[i];
const originId = originIds[i];
const originId = tag.remote_id[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

The assignment of originId using tag.remote_id[i] seems incorrect. The index i should not be used with remote_id as it's not an array but a property of the tag object.

- const originId = tag.remote_id[i];
+ const originId = tag.remote_id;

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.

Suggested change
const originId = tag.remote_id[i];
const originId = tag.remote_id;

originSource: string,
remote_data: Record<string, any>[],
): Promise<TicketingTicket[]> {
try {
let tickets_results: TicketingTicket[] = [];
for (let i = 0; i < tickets.length; i++) {
const ticket = tickets[i];
const originId = originIds[i];
const originId = ticket.remote_id[i];
Copy link
Contributor

Choose a reason for hiding this comment

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

The assignment of originId using ticket.remote_id[i] seems incorrect. The index i should not be used with remote_id as it's not an array but a property of the ticket object.

- const originId = ticket.remote_id[i];
+ const originId = ticket.remote_id;

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.

Suggested change
const originId = ticket.remote_id[i];
const originId = ticket.remote_id;

@@ -43,6 +43,7 @@ export class FrontUserMapper implements IUserMapper {
}));

const unifiedUser: UnifiedUserOutput = {
remote_id: user.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a semantic error in the assignment of the name field, where last_name is used twice instead of using both first_name and last_name.

- name: `${user.last_name} ${user.last_name}`,
+ name: `${user.first_name} ${user.last_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.

Suggested change
remote_id: user.id,
remote_id: user.id,

Comment on lines +69 to +70
//TODO
remote_id: note.Owner,
Copy link
Contributor

Choose a reason for hiding this comment

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

The addition of the remote_id field is noted with a //TODO comment, indicating unfinished work or a placeholder for future implementation. It's important to address or clarify this TODO before merging to ensure the code is complete and functional.

Would you like assistance in addressing this TODO, or should it be tracked as an issue for future resolution?

@@ -126,6 +126,8 @@ export class AttioCompanyMapper implements ICompanyMapper {

let opts: any = {};


//TODO - Logic needs to be reconsider
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO comment indicates a need for reconsidering logic related to company.values.team[0]?.target_record_id.

Would you like assistance in addressing this TODO? It's important to ensure that the logic aligns with the intended functionality and data integrity requirements.

@@ -95,6 +95,7 @@ export class HubspotCompanyMapper implements ICompanyMapper {
})) || [];

let opts: any = {};
//TODO - Logic needs to be reconsider
Copy link
Contributor

Choose a reason for hiding this comment

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

The TODO comment about reconsidering logic indicates an area that may need further attention or refinement. It's important to ensure that any logic related to owner ID mapping is correctly implemented and does not introduce inconsistencies.

Would you like me to help refine this logic or open a GitHub issue to track this task?

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: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a3b38b5 and 8686a3c.
Files selected for processing (13)
  • packages/api/src/crm/company/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/engagement/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/note/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/stage/sync/sync.service.ts (3 hunks)
  • packages/api/src/crm/task/sync/sync.service.ts (2 hunks)
  • packages/api/src/crm/user/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/account/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/comment/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/contact/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/tag/sync/sync.service.ts (3 hunks)
  • packages/api/src/ticketing/team/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/ticket/sync/sync.service.ts (2 hunks)
  • packages/api/src/ticketing/user/sync/sync.service.ts (2 hunks)
Files skipped from review as they are similar to previous changes (13)
  • packages/api/src/crm/company/sync/sync.service.ts
  • packages/api/src/crm/engagement/sync/sync.service.ts
  • packages/api/src/crm/note/sync/sync.service.ts
  • packages/api/src/crm/stage/sync/sync.service.ts
  • packages/api/src/crm/task/sync/sync.service.ts
  • packages/api/src/crm/user/sync/sync.service.ts
  • packages/api/src/ticketing/account/sync/sync.service.ts
  • packages/api/src/ticketing/comment/sync/sync.service.ts
  • packages/api/src/ticketing/contact/sync/sync.service.ts
  • packages/api/src/ticketing/tag/sync/sync.service.ts
  • packages/api/src/ticketing/team/sync/sync.service.ts
  • packages/api/src/ticketing/ticket/sync/sync.service.ts
  • packages/api/src/ticketing/user/sync/sync.service.ts
Additional Context Used

@mit-27 mit-27 closed this Mar 30, 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.

Enhance sync.services.ts to extract IDs of objects and setting the remote_ids
1 participant