Skip to content

Commit

Permalink
Fix domain name parsing on company creation (#4297)
Browse files Browse the repository at this point in the history
* add domain parsing library

* change package for psl

* trying to fix error

* fix

* update

* remove unused function
  • Loading branch information
bosiraphael authored Mar 4, 2024
1 parent aa7fa3a commit 735e75b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 8 deletions.
3 changes: 2 additions & 1 deletion packages/twenty-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
"@ptc-org/nestjs-query-graphql": "patch:@ptc-org/[email protected]#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch",
"class-validator": "patch:[email protected]#./patches/class-validator+0.14.0.patch",
"graphql-middleware": "^6.1.35",
"passport": "^0.7.0"
"passport": "^0.7.0",
"psl": "^1.9.0"
},
"devDependencies": {
"@nestjs/cli": "10.3.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class CreateCompaniesAndContactsService {
workspaceId: string,
transactionManager?: EntityManager,
) {
if (participants.length === 0) {
if (!participants || participants.length === 0) {
return;
}

Expand All @@ -51,6 +51,10 @@ export class CreateCompaniesAndContactsService {
const { uniqueParticipants, uniqueHandles } =
getUniqueParticipantsAndHandles(participantsFromOtherCompanies);

if (uniqueHandles.length === 0) {
return;
}

const alreadyCreatedContacts = await this.personService.getByEmails(
uniqueHandles,
workspaceId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ export class CreateCompanyService {
): Promise<{
[domainName: string]: string;
}> {
if (domainNames.length === 0) {
return {};
}

const uniqueDomainNames = [...new Set(domainNames)];

const existingCompanies =
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import psl from 'psl';

import { capitalize } from 'src/utils/capitalize';

export const getCompanyNameFromDomainName = (domainName: string): string => {
return capitalize(domainName.split('.').slice(-2, -1)[0]);
export const getCompanyNameFromDomainName = (domainName: string) => {
const { sld } = psl.parse(domainName);

return sld ? capitalize(sld) : '';
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export function getDomainNameFromHandle(handle: string): string {
return handle.split('@')?.[1].split('.').slice(-2).join('.').toLowerCase();
}
import psl from 'psl';

export const getDomainNameFromHandle = (handle: string): string => {
const wholeDomain = handle?.split('@')?.[1] || '';

const { domain } = psl.parse(wholeDomain);

return domain || '';
};
3 changes: 2 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -38834,7 +38834,7 @@ __metadata:
languageName: node
linkType: hard

"psl@npm:^1.1.28, psl@npm:^1.1.33":
"psl@npm:^1.1.28, psl@npm:^1.1.33, psl@npm:^1.9.0":
version: 1.9.0
resolution: "psl@npm:1.9.0"
checksum: 6a3f805fdab9442f44de4ba23880c4eba26b20c8e8e0830eff1cb31007f6825dace61d17203c58bfe36946842140c97a1ba7f67bc63ca2d88a7ee052b65d97ab
Expand Down Expand Up @@ -44289,6 +44289,7 @@ __metadata:
class-validator: "patch:[email protected]#./patches/class-validator+0.14.0.patch"
graphql-middleware: "npm:^6.1.35"
passport: "npm:^0.7.0"
psl: "npm:^1.9.0"
rimraf: "npm:^5.0.5"
typescript: "npm:^5.3.3"
languageName: unknown
Expand Down

0 comments on commit 735e75b

Please sign in to comment.