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

Fix company creation duplicate on email sync after introducing links type #6460

Conversation

bosiraphael
Copy link
Contributor

  • Introduce extractDomainFromLink
  • Use is inside create-company.service

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

The pull request addresses the issue of duplicate company creation by standardizing domain name extraction.

  • Type Annotation: Added type annotation for companyDomainNameColumnName in packages/twenty-server/src/modules/company/repositories/company.repository.ts to enhance type safety.
  • Utility Replacement: Replaced getCompanyDomainName with extractDomainFromLink in packages/twenty-server/src/modules/contact-creation-manager/services/create-company.service.ts for consistent domain extraction.
  • New Utility: Introduced extractDomainFromLink in packages/twenty-server/src/modules/contact-creation-manager/utils/extract-domain-from-link.util.ts to standardize domain extraction from URLs.

3 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings

@@ -57,7 +57,7 @@ export class CompanyRepository {
public async createCompany(
workspaceId: string,
companyToCreate: CompanyToCreate,
companyDomainNameColumnName,
companyDomainNameColumnName: string,
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Ensure companyDomainNameColumnName is always a valid column name to prevent SQL injection.

@@ -7,8 +7,8 @@ import { v4 } from 'uuid';
import { InjectObjectMetadataRepository } from 'src/engine/object-metadata-repository/object-metadata-repository.decorator';
import { CompanyRepository } from 'src/modules/company/repositories/company.repository';
import { CompanyWorkspaceEntity } from 'src/modules/company/standard-objects/company.workspace-entity';
import { extractDomainFromLink } from 'src/modules/contact-creation-manager/utils/extract-domain-from-link.util';
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Ensure extractDomainFromLink handles all edge cases to avoid inconsistencies.

@@ -55,7 +55,7 @@ export class CreateCompanyService {
},
) => ({
...acc,
[company.domainName]: company.id,
[extractDomainFromLink(company.domainName)]: company.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Consider caching results of extractDomainFromLink if called frequently.

@@ -64,7 +64,7 @@ export class CreateCompanyService {
(domainName) =>
!existingCompanies.some(
(company: { domainName: string }) =>
getCompanyDomainName(company) === domainName,
extractDomainFromLink(company.domainName) === domainName,
Copy link
Contributor

Choose a reason for hiding this comment

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

check: Verify that extractDomainFromLink correctly normalizes domain names.

@@ -0,0 +1,5 @@
export const extractDomainFromLink = (link: string) => {
const domain = link.replace(/^(https?:\/\/)?(www\.)?/i, '').split('/')[0];
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider using a more robust URL parsing library to handle edge cases and non-standard URLs.

@bosiraphael bosiraphael merged commit 77152a1 into main Jul 30, 2024
6 checks passed
@bosiraphael bosiraphael deleted the fix-company-creation-duplicate-introduced-by-domain-name-migration branch July 30, 2024 16:10
charlesBochet pushed a commit that referenced this pull request Jul 31, 2024
…type (#6460)

- Introduce `extractDomainFromLink`
- Use is inside `create-company.service`
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.

2 participants