Fix domain name parsing on company creation (#4297)

* add domain parsing library

* change package for psl

* trying to fix error

* fix

* update

* remove unused function
This commit is contained in:
bosiraphael 2024-03-04 17:50:41 +01:00 committed by GitHub
parent aa7fa3acfa
commit 735e75b3b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 28 additions and 8 deletions

View File

@ -36,7 +36,8 @@
"@ptc-org/nestjs-query-graphql": "patch:@ptc-org/nestjs-query-graphql@4.2.0#./patches/@ptc-org+nestjs-query-graphql+4.2.0.patch",
"class-validator": "patch:class-validator@0.14.0#./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",

View File

@ -28,7 +28,7 @@ export class CreateCompaniesAndContactsService {
workspaceId: string,
transactionManager?: EntityManager,
) {
if (participants.length === 0) {
if (!participants || participants.length === 0) {
return;
}
@ -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,

View File

@ -23,6 +23,10 @@ export class CreateCompanyService {
): Promise<{
[domainName: string]: string;
}> {
if (domainNames.length === 0) {
return {};
}
const uniqueDomainNames = [...new Set(domainNames)];
const existingCompanies =

View File

@ -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) : '';
};

View File

@ -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 || '';
};

View File

@ -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
@ -44289,6 +44289,7 @@ __metadata:
class-validator: "patch:class-validator@0.14.0#./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