-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Fix company creation duplicate on email sync after introducing links type #6460
Conversation
There was a problem hiding this 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
inpackages/twenty-server/src/modules/company/repositories/company.repository.ts
to enhance type safety. - Utility Replacement: Replaced
getCompanyDomainName
withextractDomainFromLink
inpackages/twenty-server/src/modules/contact-creation-manager/services/create-company.service.ts
for consistent domain extraction. - New Utility: Introduced
extractDomainFromLink
inpackages/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, |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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]; |
There was a problem hiding this comment.
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.
…type (#6460) - Introduce `extractDomainFromLink` - Use is inside `create-company.service`
extractDomainFromLink
create-company.service