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

- Introduce `extractDomainFromLink`
- Use is inside `create-company.service`
This commit is contained in:
bosiraphael 2024-07-30 18:10:36 +02:00 committed by GitHub
parent b85ae7e1ac
commit 77152a10b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 40 additions and 4 deletions

View File

@ -57,7 +57,7 @@ export class CompanyRepository {
public async createCompany(
workspaceId: string,
companyToCreate: CompanyToCreate,
companyDomainNameColumnName,
companyDomainNameColumnName: string,
transactionManager?: EntityManager,
): Promise<void> {
const dataSourceSchema =

View File

@ -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';
import { getCompanyNameFromDomainName } from 'src/modules/contact-creation-manager/utils/get-company-name-from-domain-name.util';
import { getCompanyDomainName } from 'src/utils/getCompanyDomainName';
@Injectable()
export class CreateCompanyService {
private readonly httpService: AxiosInstance;
@ -55,7 +55,7 @@ export class CreateCompanyService {
},
) => ({
...acc,
[company.domainName]: company.id,
[extractDomainFromLink(company.domainName)]: company.id,
}),
{},
);
@ -64,7 +64,7 @@ export class CreateCompanyService {
(domainName) =>
!existingCompanies.some(
(company: { domainName: string }) =>
getCompanyDomainName(company) === domainName,
extractDomainFromLink(company.domainName) === domainName,
),
);

View File

@ -0,0 +1,31 @@
import { extractDomainFromLink } from 'src/modules/contact-creation-manager/utils/extract-domain-from-link.util';
describe('extractDomainFromLink', () => {
it('should extract domain from link', () => {
const link = 'https://www.twenty.com';
const result = extractDomainFromLink(link);
expect(result).toBe('twenty.com');
});
it('should extract domain from link without www', () => {
const link = 'https://twenty.com';
const result = extractDomainFromLink(link);
expect(result).toBe('twenty.com');
});
it('should extract domain from link without protocol', () => {
const link = 'twenty.com';
const result = extractDomainFromLink(link);
expect(result).toBe('twenty.com');
});
it('should extract domain from link with path', () => {
const link = 'https://twenty.com/about';
const result = extractDomainFromLink(link);
expect(result).toBe('twenty.com');
});
});

View File

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